CSS Selector Nth-child series and Nth-of-type series differences

Source: Internet
Author: User

Nth-child is the element that selects all elements under the current parent element, while Nth-of-type represents the first element of a given type that selects a parent element.

For example, select the first P element under the p parent element, so you can write:

Parent>p:first-child or Parent>p:first-of-type, the first way to do this is that there is nothing wrong with the initial element p under the parent element. However, the first element under the parent element is not a P tag and the problem occurs. For example, the first element is span. The first P-element is not taken. The second one can normally get the first P element under the parent element. Thus. Nth-child series. is to get the element based on the parent element as a whole. The Nth-of-type, in turn, obtains the corresponding element based on a given type under the parent element.

CSS Selector Nth-child series and Nth-of-type series differences

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.