Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSteve Isaacs
2,112 PointsWhy do we say "first-child" of the li, and not the ul?
The code challenge says: "Select the li that is the first child of the ul. Set the color to white and background color to black."
and this is the right answer
li:first-child {
color: white;
background-color: black;
}
But logically shouldn't it be a ul instead of li? I mean, we are trying to target the first child of the ul. I'm confused.
2 Answers
nvcxnvkldsjaklfds
Courses Plus Student 5,041 PointsGood question. It is a child to parent relationship. Meaning first-child pseudo class targeting element from child perspective.
li:first-child{
}
The above CSS code snippet selects li element that is first child to its parent.
See! it is a whole way of seeing child - parent relationship.
I hope I answered your question.
Pedro Reis
12,315 PointsBecause first-child will be selecting every "li" element that is the first-child of its parent.