Notice that in the example above, the two li:nth-child
selector rules coincide on the eleventh li
element. Since rules that appear later in the code override earlier rules of the same type, in this case, “List 11” was given a yellow background color.
In addition to using formulas, you can also use keywords such as odd
and even
in conjunction with the :nth-child
selector. For example, :nth-child(odd)
would select all the odd-numbered child elements, while :nth-child(even)
would select all the even-numbered child elements.