There are three basic CSS selectors: Tag selector, category selector, and Id selector.
1. Tag Selector
The names of each HTML tag can be used as the names of the corresponding tag selector, such as H1, P, and so on.
2. CATEGORY Selector
The name of the category selector can be customized by the user.
Format:. Class {color: green; font-size: 20px ;}
3. Id Selector
Test with category Selector
Format: # ID {color: green; font-size: 20px ;}
Compound selector: it is a selector connected by two or more basic selectors in different ways.
There are two cases: "intersection" selector and "Union set" Selector
1. "Intersection" selector: directly connected by two selectors. The result is the intersection of the selected element ranges. The first must be the tag selector, and the second must be the category selector or ID selector, there must be no space between two selectors and continuous writing is required.
For example, h3.class {color: red; font-size: 23px ;}
2. "Union set" selector: select the range selected by each basic selector at the same time. You can select any type of selector. The Union set selector is composed of multiple selectors connected by commas,
Format: H1, H2, H3 {color: red; font-size: 23px ;}
Descendant selector:
Descendant selector writing method: the outer mark is written in front, and the inner mark is written in the back, separated by spaces. When the mark is nested, the inner Mark becomes the descendant of the outer mark.
Give a column <HTML>
<Head>
<Title> descendant selector </title>
<Style type = "text/CSS">
P span {}{
Color: red
}
Span
{}{
Color: blue;
}
</Style>
</Head>
<Body>
<P> nested <span> </P> <span> flag outside of nesting </span> is invalid.
</Body>
</Html>
The effect is: "Use CSS" to display red, others are blue surrounded by <span>
The influence of the descendant selector is not limited to the "direct descendant" of the element, but also affects its "descendants at all levels"
Sub-selector: only the selector that has an influence on the direct descendant, but does not play a role on the "grandson" and the descendant of individual layers.
Format: P> span {color: Blue ;}