Not supported by IE, Firefox and Safari.
The :nth-child() and :nth-of-type() pseudo-classes allows you to select
elements with a formula.
The syntax is :nth-child(an+b), where you replace a and b by numbers
of your choice. For instance, :nth-child(3n+1) selects the 1st, 4th, 7th etc. child.
:nth-of-type() works the same, except that it only considers element of the given type (<li>
in the example).
Test sheet:
ol > :nth-child(3n+1) {
color: red;
}
li:nth-of-type(5n+2) {
color: blue;
}
The paragraphs count for the :nth-child() selector, but not for the :nth-of-type()
selector.
Paragraph
Paragraph