CSS3 :nth-child() Selector
Specify a foundation shading for each <p> component that is the second offspring of its parent:
More "Attempt it Yourself" models below.
Definition and Usage
The :nth-child(n) selector coordinates each component that is the nth tyke, paying little mind to type, of its parent.
n can be a number, a catchphrase, or a formula.
Tip: Look at the :nth-of-type() selector to choose the component that is the nth kid, of a specific type, of its parent.
The numbers in the table determines the principal program form that completely underpins the selector.
Odd and even are watchwords that can be utilized to coordinate youngster components whose file is odd or even (the record of the main tyke is 1).
Here, we determine two diverse foundation hues for odd and even p elements:
Using an equation (an + b). Depiction: a speaks to a cycle measure, n is a counter (begins at 0), and b is an counterbalance value.
Here, we indicate a foundation shading for all p components whose list is a numerous of 3: