Home >Web Front-end >CSS Tutorial >'Different Types of CSS Selectors”

'Different Types of CSS Selectors”

Linda Hamilton
Linda HamiltonOriginal
2025-01-06 18:15:43553browse

Types of Selectors in CSS:

Class Selector:

Code:

<body>
    <p>





<pre class="brush:php;toolbar:false"><style>
.heighlight {
    color: red;
    font-weight: bold;
}
</style>

Id Selector:

Code:

<body>
    <h1>





<pre class="brush:php;toolbar:false"><style>
#main-heading {
    color: blue;
    font-size: 24px;

}

#intro-paragraph {
    background-color: yellow;
    padding: 10px;

}
</style>

Elementor Selector:

<body>
    <h1>Welcome to My Website</h1>
    <p>This is a paragraph</p>
    <p>This is another paragraph</p>
    <a href="https:///www.google.com">Visit Example Website</a>
</body>
<style>
    h1 {
        color: blue;
    }
    p {
      font-size: 16px;

    }
    a {
        text-decoration: none;
        color: red;
    }
</style>

Universal Selector

Code:

<body>
    <h1>Welcome to My Website</h1>
    <p>This is a paragraph</p>
    <div>
        <h2>About Us</h2>
        <p>This is another paragraph</p>
    </div>
</body>
<style>
*{
    margin: 0;
    padding: 0;
    border: 1 px solid;
}
</style>

Grouping Selector:

Code:

<body>
    <h1>Welcome to My Website</h1>
    <p>This is a paragraph.</p>
    <a href="#">Click me</a>
    <button>Submit</button>
</body>
<style>
    h1,p {
        color: blue;
    }
    a,button {
        background-color: yellow;
        padding: 10px;
    }
</style>

Attribute Selector:

Code:

<form>
    <label for="name">Name:</label>
    <input type="text">





<pre class="brush:php;toolbar:false"><style>
    input[type="submit"] {
        background-color: #4caf50;
        color: white;
    }
    input[required] {
        border: 1px solid red;
    }
</style>

The above is the detailed content of 'Different Types of CSS Selectors”. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn