Target Pseudo class selector ": Target" is used to match the target element of an identifier in the document's URI. Specifically speaking. Identifiers in URIs usually contain a # number followed by an identifier name, such as "#contact" and ": Target" to match the element with the id "contact".
Use pure CSS to achieve vertical accordion effects.
V. Structure pseudo-Class selector
<! DOCTYPE html>
Page Initial effect
1. :first-child Use of
ul > li:first-child{ background-color: green;}
2. :last-child Use of
ul > li:last-child{ background-color: blue;}
3. :nth-child Use of
ul > li:nth-child(3){ background-color: yellow;}
ul > li:nth-child(n){ background-color: yellow;}
ul > li:nth-child(2n){ background-color: yellow;}
ul > li:nth-child(2n+1){ background-color: yellow;}
ul > li:nth-child(n+5){ background-color: blue;}
ul > li:nth-child(-n+5){ background-color: blue;}
ul > li:nth-child(4n+1){ background-color: blue;}
4. :nth-last-child Use of
:nth-last-childand :nth-child similar, just :nth-last-child starting from the last child element of a parent element to select a specific element.
ul > li:nth-last-child(4){ background-color: blue;}
5. :nth-of-type Use of
:nth-of-typeand :nth-child Similar, the difference is that it only calculates the child elements of a certain type specified in the parent element. It :nth-of-type is useful and convenient to use selectors to locate child elements of a certain type in a parent element when child elements in an element are not just child elements of the same type.
6. :nth-last-of-type Use of
:nth-last-of-type:nth-of-typeis used to select a SEED element type specified in the parent element, but it starts from the last child element.
7. :first-of-type and :last-of-type the use of
:first-of-type:last-of-typesimilar to and to these two selectors :first-child , the :last-child difference is that the type of the element is specified. In other words, :first-of-type it is used to locate the first child element of a type under a parent element. It is :last-of-type used to locate the last child element of a type under a parent element.
8. :only-child Use of
:only-childIndicates that an element is the only child element of its parent element. In other words, there is only one child element in the parent element of the matching element.
<!DOCTYPE html>
Page Initial effect:
.post > p:only-child{ border-width: 2px; background-color: #000;}
9. :only-of-type Use of
:only-of-typeThe only child element of the same type that is used to select an element that is its parent element. In other words, it :only-of-type means that an element has many child elements, and that only one child element is unique and :only-of-type can be used to select a child element of that unique type.
:emptyuse of ten.
:emptyThe element used to select any content, "no content" here refers to a little bit of content, even if it is a space.
VI. Pseudo-Elements
Pseudo-elements can be used to locate text contained in a document, but cannot be positioned in the document tree. CSS3 the pseudo-elements in a certain adjustment, on the basis of the previous addition of a colon, corresponding to the,,,, and ::first-letter ::first-line ::before ::after also added a ::selection .
1. ::first-line and ::first-letter the use of
<!DOCTYPE html>
Seven, attribute selector
The format of the property selector is the following:,,,,, E[attr] E[attr=val] E[attr|=val] E[attr~=val] E[attr*=val] E[attr^=val] , E[attr$=val] .
<! DOCTYPE html>
Page Initial effect
1.E[attr]
a[id]{ background-color: yellow;}
a[id][title]{ background-color: red;}
2.E[attr=val]
a[id=first]{ background-color: red;}
3.E[attr|=val]
a[lang|=zh]{ background-color: yellow;}
4.E[attr~=val]
a[title~=website]{ background-color: yellow;}
5.E[attr*=val]
a[class*=links]{ background-color: red;}
6.E[attr^=val]
a[href^=http]{ background-color: yellow;}
7.E[attr$=val]
a[href$=png]{ background-color:yellow;}
CSS3 Selector Learning Notes