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

Chase Boothe
Chase Boothe
1,353 Points

:only-child not working

:only-child is not working for me... what could be the problem...

:only-child { background: lightcoral; }

2 Answers

You should specify a selector before :only-child, for example:

p:only-child { background: lightcoral; }

or

#div ul li a:only-child { background: lightcoral; }

I was having this same issue and found your question. One thing to note is that Guil does not specify a selector in this video when he is on this step, and yet it works for him. I took a screenshot, but it can be seen around 4:07 in this video that he puts :only-child without any selector in front of the colon.