CSS3: Nth-child and: The difference of nth-of-type in depth understanding

Source: Internet
Author: User

about: Nth-child and: Nth-of-type The difference has not been too much attention. Recently intends to dig deeper into some CSS3, only to discover inside actually hidden mystery.

: Nth-child can select the Word element under the parent element: Nth-of-type can also. But what difference do they have?

In fact the difference is very simple:: Nth-of-type Why to call: Nth-of-type? Because it is differentiated by "type". In other words: Ele:nth-of-type (n) refers to the nth ele element under the parent element,

ele:nth-child (n) refers to the nth element under the parent element and the element is ele, if not, the selection fails.

A small example is attached here:
 The code is as follows:
<div>
<ul class= "Demo" >
<p>zero</p>
<li>one</li>
<li>two</li>
</ul>
</div>
In This example, the. Demo Li:nth-child (2) selects the <li>one</li> node, and the. Demo Li:nth-of-type (2) is selected <li>two</li > node. Original: http://www.jb51.net/css/142398.html

CSS3: Nth-child and: The difference of nth-of-type in depth understanding

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.