CSS CSS Basics 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 :-)

Reggie Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
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.