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

For the decendent selector, couldnt you use the "address p" to target the P element? Do you have to use header element?

Could you write it this way as well?

address p { color: red; }

Steven Parker
Steven Parker
231,248 Points

For help with providing enough information for a precise answer, take a look at this video about Posting a Question.

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

Can you please provide the HTML that you are trying to style? It would help narrow down exactly what you mean.

I will make an assumption that you have something setup like this:

<header>
   <address>
       <p>Address text</p>
   </address>
</header>

And that you're asking if you can just use address p {} to target the paragraph tag.

You would be correct! However, there is a pretty big caveat. The problem is, you will be targeting all paragraphs that are children of address tags. When it comes the the specificity of selectors you always want to be a precise as you can be. If you are okay with selecting all of the address paragraph tags, then you are fine. However, if we have something like this:

<header>
   <address>
       <p>Address text</p>
   </address>
</header>
<div>
   <address>
     <p>More Address text</p>
   </address>
</div>

Then you'll also be selecting the address text inside of the div, which may not be what you want. (The better selector would honestly be making one of those a class and then using a descendent selector on that class, but that's a different thing).

So that's probably why they did something like header address p {} to target that specific paragraph.

Now I'm making a bunch of assumptions, which is why it's important to show your code when asking questions! :)