CSS3 :nth-of-type() Selector
Specify a foundation shading for each <p> component that is the second p component of its parent:
More "Attempt it Yourself" models below.
Definition and Usage
The :nth-of-type(n) selector coordinates each component that is the nth youngster, of a specific sort, of its parent.
n can be a number, a catchphrase, or a formula.
Tip: Look at the :nth-child() selector to choose the component that is the nth youngster, regardless of type, of its parent.
The numbers in the table determines the main program form that completely underpins the selector.
Odd and even are watchwords that can be utilized to coordinate kid components whose file is odd or even (the list of the primary kid is 1).
Here, we determine two distinctive foundation hues for odd and even p elements:
Using a formula (an + b). Description: a represents a cycle size, n is a counter (starts at 0), and b is an offset value.
Here, we specify a background color for all p elements whose index is a multiple of 3: