0
0
CSSmarkup~5 mins

Nth-child selector in CSS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the :nth-child() selector do in CSS?
It selects elements based on their position among siblings in the parent element. For example, :nth-child(2) selects the second child element.
Click to reveal answer
beginner
How would you select every even child element using :nth-child()?
Use :nth-child(even). This selects the 2nd, 4th, 6th, and so on children.
Click to reveal answer
intermediate
What does :nth-child(3n+1) select?
It selects every 3rd element starting from the first child. So, 1st, 4th, 7th, 10th, etc.
Click to reveal answer
beginner
True or False: :nth-child() counts only elements of a specific type.
False. :nth-child() counts all child elements regardless of type. To select specific types, use :nth-of-type().
Click to reveal answer
beginner
How can :nth-child() help in creating striped table rows?
By selecting even or odd rows with tr:nth-child(even) or tr:nth-child(odd), you can style alternating rows differently for better readability.
Click to reveal answer
Which CSS selector targets every 3rd child starting from the second child?
A:nth-child(3n-2)
B:nth-child(2n+3)
C:nth-child(2n+1)
D:nth-child(3n+2)
What does :nth-child(odd) select?
AAll children at odd positions (1st, 3rd, 5th...)
BAll children at even positions
COnly the first child
DOnly the last child
If you want to style only the 4th child element, which selector do you use?
A:nth-child(even)
B:nth-child(3n)
C:nth-child(4)
D:nth-child(odd)
Does :nth-child() consider element types when counting children?
AYes, it counts only elements of the same type
BNo, it counts all child elements regardless of type
CIt counts only text nodes
DIt counts only elements with a class
Which selector would you use to color every even row in a table?
Atr:nth-child(even)
Btr:nth-child(odd)
Ctr:nth-of-type(odd)
Dtr:nth-of-type(even)
Explain how the :nth-child() selector works and give an example of using a formula inside it.
Think about how you count items in a list and how formulas can pick certain positions.
You got /3 concepts.
    Describe the difference between :nth-child() and :nth-of-type() selectors.
    Consider if you want to select all children or only specific tags.
    You got /3 concepts.