Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the difference between nth-child and: nth-of-type in CSS3

Shulou Source: shulou.com Published: 2022-06-03 17:55:30 11月13日 Update

This article mainly introduces the difference between CSS3: nth-child and: nth-of-type, which has certain reference value, interested friends can refer to, hope you can learn a lot after reading this article, let the editor take you to understand it.

: nth-child can select the word element under the parent element, or: nth-of-type can. But what's the difference between them?

In fact, the difference is very simple: why is nth-of-type called nth-of-type? Because it is distinguished by "type". That is to say: ele:nth-of-type (n) refers to the nth ele element under the parent element, while ele:nth-child (n) refers to the nth element under the parent element and this element is ele, if not, the selection fails.

A small example is attached here:

Zero

One two

In the above example, .demo li:nth-child (2) selects the one node, while .demo li:nth-of-type (2) selects the two node.

Thank you for reading this article carefully. I hope the article "in CSS3: what is the difference between nth-child and nth-of-type" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Elements articles selections examples nodes that is value interest at the same time more friends knowledge editing industry information information channels channels references learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Docker Redmi Apple Linux