Selectors

 Selectors




In CSS, selectors target HTML elements to apply styles. Here’s a breakdown of common CSS selectors and how they are used:


  • Element Selector

Targets all instances of a specific HTML tag.

element {

    /* Styles applied to all <element> tags */

}


  • Class Selector
Targets elements with a specific class. The dot (.) symbol is used to select classes.

.a {

    /* Styles applied to all elements with class "a" */

}


  • ID Selector
Targets a specific element with an id attribute. The hash (#) symbol is used to select IDs.

#id {
    /* Styles applied to the element with id "id" */
}


  • Multiple Classes Selector
Targets elements that have both class a and class b.

.a.b {
    /* Styles applied to elements with both "a" and "b" classes */
}


  • Universal Selector (*)
Targets all elements in the document.

* {
    /* Styles applied to all elements */
}


Example Usage:

<div class="a b" id="id">Content</div>


div { /* targets all <div> elements */}
.a { /* targets elements with class "a" */}
#id { /* targets the element with id "id" */}
.a.b { /* targets elements with both classes "a" and "b" */}
* { /* targets all elements in the document */}






Output will appear here...

Post a Comment

0 Comments