CSS Pseudo-class :nth-of-type
This selector selects every nth child-element of the given type by using the formula an+b. a
and b
are integers. If you want to select every third p which is a child of the element body
starting with the first p
, you write body > p:nth-of-type(3n+1)
. This will select every first, fourth, seventh (and so on) p
that is a child of body
. This also works if there are other elements or text between the children. Instead of an+b
you can use the keywords even
and odd
that are equal to 2n
and 2n+1
.
Examples
Compatibility
Chrome | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|
All | All | 9+ | 9.5+ | 3.2+ |