CSS Selectors
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
We can divide CSS selectors into five categories:
- Simple selectors (select elements based on name, id, class)
- Combinator selectors (select elements based on a specific relationship between them)
- Pseudo-class selectors (select elements based on a certain state)
- Pseudo-elements selectors (select and style a part of an element)
- Attribute selectors (select elements based on an attribute or attribute value)
This page will explain the CSS simple selectors.
The CSS element Selector
The element selector selects HTML elements based on the element name.
p {
text-align: center;
color: red;}
Every paragraph will be affected by the style.p {
text-align: center;
color: red;}
All CSS Simple Selectors
Selector | Example | Example description |
---|---|---|
.class | .intro | Selects all elements with class="intro" |
#id | #firstname | Selects the element with id="firstname" |
* | * | Selects all elements |
element | p | Selects all <p> elements |
element,element,.. | div, p | Selects all <div> elements and all <p> elements |
Me too!
And me!
0 коммент.