CSS pseudo-Class selector

Source: Internet
Author: User

The pseudo-class selector for CSS is really love and hate, each time is very perfect to be confused, or to do a summary.

: Last-of-type Select last element

<Divclass= "box">    <P>1 always believe in good things</P>    <a>2 is about to happen</a>    <P>3 always believe in good things</P>    <P>4 always believe in good things</P>    <a>5 is about to happen</a>    <a>6 is about to happen</a></Div>
P:last-of-type { background: red;}

: First-of-type Select the first element

<Divclass= "box">    <P>1 always believe in good things</P>    <a>2 is about to happen</a>    <P>3 always believe in good things</P>    <P>4 always believe in good things</P>    <a>5 is about to happen</a>    <a>6 is about to happen</a></Div>
A:first-of-type { background: red;}

: Nth-child (n) Select the nth child element of the parent element

1 <Divclass= "box">2     <P>1 always believe in good things</P>3     <a>2 is about to happen</a>4     <P>3 always believe in good things</P>5     <P>4 always believe in good things</P>6     <a>5 is about to happen</a>7     <a>6 is about to happen</a>8 </Div>
The second child element must be a, otherwise invalid

A:nth-child (2){ background: red;}

: Nth-last-child (n) Select the last nth child element of the parent element

1 <Divclass= "box">2     <P>1 always believe in good things</P>3     <a>2 is about to happen</a>4     <P>3 always believe in good things</P>5     <P>4 always believe in good things</P>6     <a>5 is about to happen</a>7     <a>6 is about to happen</a>8 </Div>
The penultimate must be a, otherwise invalid

A:nth-last-child (2){ background: red;}

CSS pseudo-class selector

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.