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 trial

CSS CSS Foundations Selectors Basic Structural Pseudo-Classes

Matthew Beiswenger
Matthew Beiswenger
6,814 Points

will pseudo elements apply to all?

for example, will li:first-child apply to the first child of ALL list items? I'm assuming it does, but it wasn't explicitly specified in the video.

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Matthew,

Yes li:first-child will apply to all list items you attach the first-child pseudo selector to. But you can get around this by simply selecting it to an ID or a class, so you could use

li#firstchild-id:first-child or

li.firstchild-class:first-child

And it would not effect any other lists on your page. :-)

Matthew Beiswenger
Matthew Beiswenger
6,814 Points

Thanks for the quick response! Being able to add a class or an id to the child selectors definitely makes the last and fist child pseudo elements more useful

James Barnett
James Barnett
39,199 Points

If you haven't already, later on in CSS you'll learn about the magic of specificity. Then a lot of the more advanced selectors make a lot more sense.