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

'Different Types of CSS Selectors”

Linda Hamilton
Release: 2025-01-06 18:15:43
Original
502 people have browsed it

Types of Selectors in CSS:

Class Selector:

Code:

<body>
    <p>





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

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>

Copy after login

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>
Copy after login
<style>
    h1 {
        color: blue;
    }
    p {
      font-size: 16px;

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

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>
Copy after login
<style>
*{
    margin: 0;
    padding: 0;
    border: 1 px solid;
}
</style>
Copy after login

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>
Copy after login
<style>
    h1,p {
        color: blue;
    }
    a,button {
        background-color: yellow;
        padding: 10px;
    }
</style>
Copy after login

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>
Copy after login

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!

source:dev.to
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template