The selectors in CSS include: 1. Simple selector; 2. Attribute selector; 3. Combination selector; 4. Pseudo-class selector; 5. Pseudo-element selector; 6. Multiple selector.
Selector | Meaning |
---|---|
Universal element selector, matches any element | |
Tag selector, matches all elements using the E tag | |
class selector , matches all elements containing info in the class attribute | |
id selector, matches all elements whose id attribute is equal to footer |
Meaning | |
---|---|
Selects all elements containing the attr attribute, regardless of the value of attr | |
[attr=val] Select only all elements whose attr attribute is assigned to val |
Meaning | |
---|---|
Select elements matching A or/and B | |
Select the descendant elements that match B and are the elements that match A (space separates A and B) | |
Select the element that matches B and is the direct child element of the element that matches A | |
Select the element that matches B and is the next element that matches A Adjacent elements | ##A ~ B |
a:visited | |
a:hover | |
a:active | |
li:first-child | |
li:last-child | |
##li:nth-child(n) | |
5. Pseudo-elements |
E::after | |
E::selection | |
E::first-letter | |
E ::first-line | |
6. Multiple Selectors Multiple Selectors |
<p class="one two"></p>
.one .two{} /*两个 class 中有空格*/ .one.two{} /*两个 class 中沒有空格*/ .one, .two{} /*两个 class 中出现逗号*/Copy after login. What is the difference between
one.two{ },
.one .two{ }, or
There is no space between the second one and two, which means that a certain block must have both one and two classes before it can be selected by CSS..one, .two{ }
?The first one and two contain a space between them, which means that I must be two in one to be selected.
css video tutorial
- The third one and two contain commas, which means that if there is one or two in the class, it will be selected by the editor.
- Simply put, no spaces means that they must be included at the same time to be selected; spaces mean that the following class will be selected if it is embedded in the previous class; comma means that only one of the classes must be included will be selected.
- [Recommended learning: "
"]
The above is the detailed content of What selectors are there in css?. For more information, please follow other related articles on the PHP Chinese website!