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 Basics (2014) Basic Selectors Descendant Selectors

Can you pair ID and Class selectors together when creating a Descendent Selector?

Since you can pair an ID and class selector with a type/element selector in order to create a descendent selector could you do the same with ID and class? for example, say your HTML looks like this:

<header class="main"> <p id="first">This is my first paragraph</p> </header>

could you then create a decedent selector pairing the class of the header with the ID of the p element in order to apply a CSS rule to that specific p tag? like this

.main #primary {padding: 10px;}

or since any rules applied to ID's overrule any rules applied to classes would this end up not working out? or could you do the inverse if your HTML looked like this:

<header id="main"> <p class="primary>This is my primary paragraph</p> </header>

#main .primary {margin: auto;}

Just curious any insight is appreciated :-)

1 Answer

Reggie Williams
STAFF
Reggie Williams
Treehouse Teacher

Hey sarahmoore4 you can absolutely pair/combine selectors in this way! I'd also suggest anytime you are wondering if something will work to give it a try in the browser, if you run into any errors the community is always happy to assist. Great work thinking like a programmer and applying the concepts you've learned.