Recall & Review
beginner
What does the CSS selector
:first-child do?It selects the very first child element inside its parent element.
Click to reveal answer
beginner
What does the CSS selector
:last-child do?It selects the very last child element inside its parent element.
Click to reveal answer
intermediate
Can
:first-child select the first element of a specific type only?No,
:first-child selects the first child regardless of its type. To select the first of a specific type, use :first-of-type.Click to reveal answer
beginner
How would you style only the first paragraph inside a
<div> using :first-child?Use
div p:first-child { /* styles */ }. This styles a p only if it is the first child of the div.Click to reveal answer
beginner
What happens if you use
:last-child on an element that is not the last child?The style will not apply because
:last-child only matches elements that are the last child of their parent.Click to reveal answer
Which CSS selector targets the first child element of its parent?
✗ Incorrect
:first-child selects the first child element inside its parent.What does
li:last-child select?✗ Incorrect
li:last-child selects the li element that is the last child of its parent.If a
p is the second child of a div, will div p:first-child style it?✗ Incorrect
:first-child matches only if the element is the first child of its parent.Which selector would style the last
li in a list?✗ Incorrect
li:last-child targets the last li inside its parent.What is true about
:first-child and :last-child selectors?✗ Incorrect
Both selectors select elements based on their position as first or last child among siblings.
Explain how the
:first-child and :last-child selectors work in CSS.Think about how these selectors depend on the element's position among siblings.
You got /3 concepts.
Describe a real-life example where you would use
:first-child or :last-child in styling a webpage.Consider menus, lists, or groups of items on a page.
You got /3 concepts.