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 Advanced Selectors Pseudo-Classes: :nth-of-type and :only-of-type

Carlos Serrano
Carlos Serrano
3,351 Points

Setting <p> attributes into divs

Hello. Can anyone tell me how to make the <p> element inside the divs a different color than the one outside for this exercise? Thank you

Could you be more specific please?

4 Answers

Daniel Aguirre
Daniel Aguirre
4,498 Points

Use Span on the HTML ex: <span>Hi world</span> is easier

Andrew McCormick
Andrew McCormick
17,730 Points

Carlos Serrano , posting your code or an example of your html code would help.
It sounds like you just need to have more specific selectors. Example:

<h1>This would be green</h1>
<div id="content">
  <h1>This would be red</h1>
</div>
h1 {
color: green;
}

#content h1 {
color: red;
}

working example

Carlos Serrano
Carlos Serrano
3,351 Points

Thank you guys. I thought discussions were related to each lesson by default. Sorry for not being more specific. I was referring to the Pseudo-Classes-nth-of-type and:only-of-type lesson under Web Design / Advanced Selectors. On 5:05 the instructor is adding text to some previously created divs. I was wondering how to select the text "inside the divs" only and add for example a different color "just" to this element. Thank you

Andrew McCormick
Andrew McCormick
17,730 Points

Oh. you are looking for div > p:only-of-type {} See Updated Example Codepen

Carlos Serrano
Carlos Serrano
3,351 Points

Thank you Andrew. This is exactly what I needed.