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 Using Combinators in Selectors

need help with selectors

div > p { color: green; font-weight: bold; }

error: child selector uses >, make sure to set color to green.

can anyone point me in the right direction Thanks

4 Answers

This is the answer :

div a{
    color :green;
  font-weight:bold;
}
div p{
    background: lightblue;
}

Try it and tell me the result

This does pass so I believe this challenge has an error in it. It's asking to target direct children so you should be using >

The descendant selector you have above, div a, should not be passing the challenge.

I did that and it's working even in my text editor

Hi Dustin,

Whether you notice a difference between div a and div > a is going to depend on the html.

If you look at the html in the challenge you will see that there are two links which are direct children of the div but there's also a link in the last paragraph. This link is not a direct child of the div. So there are 3 links total in that div.

If you do this:

div a {
    color: green;
}

That's going to target all descendant links of the div. So all 3 links will be green.

If you do this:

div > a {
    color: green;
}

Only the 2 direct child links of the div will be green. The link in the paragraph will not be affected by this.

So depending on what html you have you may or may not notice a difference between these two but there is an important difference between the two selectors.

Yeah 100% you are right but when you do this in the challenge it will not accept. In the first time I got into this challenge I did div > p it says wrong then I tried div p then it works it's a bug I think

Are you talking about task 2 now? I thought the original question was about task 1.

I just checked task 2 and it passed with both div p and div > p but neither of these selectors should pass.

You're supposed to use the adjacent sibling selector h2 + p This will target paragraphs that immediately follow an h2

Guil Hernandez This challenge seems to be passing with incorrect answers.

Hi Kent,

The challenge wants you to target the anchor element that is a direct child of the div whereas you've targeted the paragraph that is a direct child of the div. Everything else looks good. You're using the correct combinator >

This particular error message is misleading.

thanks for the help

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Thanks, Jason Anello . I'll take a look at why this is happening. :)

Thanks, Guil