This article will give you a detailed introduction to the composite selector in CSS, and learn about the intersection selector, union composite selector, hierarchical selector, pseudo-class and pseudo-element selector, and attribute selector in CSS, together Study it!
two selectors, the first of which One is the label selector, and the second one is the class selector or id selector; 2. There can be no spaces between the two selectors
div.student{ color: red; }
comma
p.slogn,.teacher,#gy{ font-family: "宋体"; }
1. Descendant element compounder
#yuGong .people{ color: red; }
all the descendants of people willdye their hair, including Yugong’s son, grandson, great-grandson...
2. Sub-elements Composite selector
#yuGong>.people{ color: red; }
sons among Yu Gong's descendants will dye their hair. Yu Gong's grandsons and great-grandsons will not dye their hair because Still young Only child elements (biological sons) will be selected here
3. Nearby brother selector
same parent, and the second element must closely follow the first element
#secondBaby+#thirdBaby{ color: red; }
4. Ordinary brother selector
the same parent , but the second element does not have to follow the first element.
#bigBaby~#thirdBaby{ color: red; }
#0. What is "pseudo"?
1. Pseudo-class selector
status pseudo-classes that are not explained in detail above
1) link
a:link{...}
2) visited
a:visited{...}
3)hover
a:hover{...}
4) activer
a:active{...}
5) focus
a:focus{...}
Note: Do not reverse the order of pseudo-classes, follow the order of link-visited-hover-active, otherwise errors may occur
2. Pseudo-element selector
Function: Used to create some elements that are not in the document tree and add styles to them.
Selector | Function | Format |
---|---|---|
::first-letter | Select the first letter of the selector | p::first-letter |
Select the first line of the selector | p::first-line
|
|
Add content before the selector and use the content attribute to specify the content to be inserted. (The inserted content is not actually in the document tree) | p::before{content: "hello ";}
|
|
Add content after the selector and use the content attribute to specify the content to be inserted. (The inserted content is not actually in the document tree) | p::after{content: "hello ";}
|
|
Matches the part selected or highlighted by the user | p::selection
|
Function | Format | |
---|---|---|
Indicates that the att attribute value of the E tag starts with 'value' | p[id^='yuan' ]{color: red;} | |
Indicates that the att attribute value of the E tag ends with 'value' | p[id$='chao']{ color: blue;} | |
represents the att attribute value of the E tag Contains the 'value' string | p[class*='shi']{font-size: 35px;} |
Introduction to Programming! !
The above is the detailed content of CSS selector learning: Let's talk about compound selectors (detailed introduction). For more information, please follow other related articles on the PHP Chinese website!