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
.) symbol is used to select classes..a {
/* Styles applied to all elements with class "a" */
}
- ID Selector
id attribute. The hash (#) symbol is used to select IDs.#id {
/* Styles applied to the element with id "id" */
}
- Multiple Classes Selector
a and class b..a.b {
/* Styles applied to elements with both "a" and "b" classes */
}
- Universal Selector (
*)
* {
/* Styles applied to all elements */
}
<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...
0 Comments