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

:only-child structure issues

Ok so im doing the video on structural Pseudo classes and everything is going right and then i get to the :only-child structure and the background wont fill on my unordered list. anybody know what to do? could i possibly put a <div> tag around the whole list and style it with a class

6 Answers

Nick Seville
Nick Seville
12,020 Points

Can you post what your code looks like? Make sure that you check and see if you have any other children elements on the same level as the ul element.

If there are any sibling elements to the ul then :only-child will not target it.

If this information doesn't help I can give some further guidance after checking out the code.

here it is. i have no idea why it wont style. thanks nick

<code> li:first-child { background-color:steelblue; color:white; border:none; }

li:last-child { background-color:steelblue; color:white; border: none; }

:only-child { background-color: }</code>

i just realized i didnt paste the background-color in the :only-child selector. still didn't work when i added a color idk

Nick Seville
Nick Seville
12,020 Points

:only-child { background-color: blue; } A couple things you can check - 1.) You had said that you forgot to add a color to your background-color declaration, double check and make sure you placed a ; at the end. 2.) Check your html structure and make sure that the ul has no siblings. If it has any siblings then it will not be selected.

example - This div element contains 2 ul elements, thus neither element is the only child. However each ul contains only one li so both of those would be targeted. <div> <ul> <li> </li> </ul>

<ul> <li> </li> </ul> </div>

Sorry if this is formatted poorly. I am experimenting and trying to figure out how to make it look right. The link Treehouse has to the Markdown Cheatsheet doesn't work.

cool ill check it out and see what happens

ok so i figured out the :only-child selector. if you specify the ul befote the selector it works, maybe i missed this step but it works like this ul:only-child{ }