CSS3---nth-of-type (n) Selector

Source: Internet
Author: User

Nth-of-type (n) Selector

The :nth-of-type(n) selector and the selector are :nth-child(n) very similar, except that it calculates only the child elements of one of the types specified in the parent element. When a child element in an element is not just a child of the same type, it is convenient and useful to use the ": Nth-of-type (N)" selector to locate a child element of some type in the parent element . In the ": Nth-of-type (N)" selector the "n" and ": Nth-child (N)" selectors in the "n" parameter also the same, can be a specific integer , can be an expression , or it can be a keyword .

Sample Demo

With the ": Nth-of-type (2n)" selector, set the background of the number of even segments in the container "div.wrapper" to orange.

HTML code:

<div class= "wrapper" >  <div> I am a div element </div>  <p> I am a paragraph element </p>  <div > I am a div element </div>  <p> I am a paragraph </p>  <div> I am a div element </div>  <p> I am a paragraph </p>  <div> I am a div element </div>  <p> I am a paragraph </p>  <div> I am a DIV element </div>  <p> I'm a paragraph </p>  <div> I'm a div element </div>  <p> I'm a paragraph </p >  <div> I'm a div element </div>  <p> I'm a paragraph </p>  <div> I'm a DIV element </div >  <p> I'm a paragraph </p></div>

CSS code:

. wrapper > P:nth-of-type (2n) {  background:orange;}

Demo Result:

CSS3---nth-of-type (n) 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.