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


alex mattingley
alex mattingley
7,508 Points

Child Selectors question

I am working through the code challenge for the second part on beginner selectors and the first question asks you to use a Child Selector to select the anchor element that is a direct child of the div. Set its color to green and the font weight to bold.

Here is the HTML code that they are refering to:

<h1>Lorem ipsum dolor sit</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pulvinar consequat tortor, nec venenatis erat elementum scelerisque. Curabitur sit amet risus nisi. Aenean aliquet euismod augue at viverra. Ut varius arcu in <a href="#" title="foo">lorem iaculis ullamcorper</a>.</p>
    <h2>Donec tempor sodales</h2>
    <p>Sed tincidunt rutrum enim, vitae pharetra justo suscipit a. Nam eu egestas risus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam tempor, augue quis.</p>
    <a href="#">Donec eget lorem id nisi vehicula...</a>
    <p>Sed sit amet nulla elit, vel lacinia nisi. Donec eget lorem id nisi vehicula auctor id et dui. Etiam aliquet aliquet sem in rutrum. Cras posuere pharetra sem vitae egestas.</p>


My first response was to say that the p element was the direct child. Isnt that correct?

1 Answer

David Lane
David Lane
33,414 Points

Hey Alex,

While the paragraph is the first element in that div, it is not the only direct child. The question you are referring to is asking you to target the anchor tags in that are children of that div. Your CSS will be same as if you were selecting the paragraph tags, just use the anchor selector instead.

For example if you wanted to select all the children elements that where images, your CSS would look like:

div img { CSS RULES }

alex mattingley
alex mattingley
7,508 Points

Ahha, now that makes sense. I just missed that part of the question. I actually just started selecting all of the elements in the div until I got the right answer to pass the question, but I just wanted to make sure that all different elements could be children and not just anchor tags.

thanks for your help David!