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?
✗ Incorrect
The formula 3n+2 selects children at positions 2, 5, 8, etc.
What does
:nth-child(odd) select?✗ Incorrect
odd matches 1, 3, 5, and so on.If you want to style only the 4th child element, which selector do you use?
✗ Incorrect
:nth-child(4) targets exactly the 4th child.Does
:nth-child() consider element types when counting children?✗ Incorrect
:nth-child() counts all child elements, not filtered by type.Which selector would you use to color every even row in a table?
✗ Incorrect
tr:nth-child(even) selects even rows for styling.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.