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 trialJason Anders
Treehouse Moderator 145,860 PointsClarity on "child" of "parent"
I understand pseudo classes and can code them when need be, but I'm still confused on why you would code
li:first-child {};
to target the first child in a list. Wouldn't it be the "first-child" of the 'ul' and not the "first-child" of the 'li'?
1 Answer
Marcus Parsons
15,719 PointsHey Jason,
The "first-child" pseudo class is used to represent any element that is the first child element of its parent element. You call "first-child" on the child selector you wish to target, not on the parent element. From the MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/:first-child
Joshua Erskine
7,706 PointsJoshua Erskine
7,706 PointsAgree, the language is rather counter-intuitive. A more accurate name would be first-occurrence-as-a-child, but that is rather long.