In the css selector, why can't the nth-child selector select the first one?

Mar.05,2021

nth-child is a child element under the selected parent element, with subscript starting at 1

p:nth-child (3n + 0) indicates the selection of 3,6 under the parent element of p element. Child element, if you want to select the first element, write as follows: nth-child (1), similarly: nth-child (3n + 1) represents the selection of 1, 4, 7. A sub-element of size.

it should be noted here that the first child of the parent element of the p element is the H1 tag, so if you want to select the parent element of the p element, 1, 4, 7. P elements, using: nth-child need to be written as: nth-child (3n + 2). However, it is recommended that you use nth-of-type (3n+1)

.
Menu