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!

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 Review

I have been meaning to set this up firmly in my mind for weeks:

Background: let's say I have HTML with class="classOne" and class="classTwo".

On the style sheet:

this is and AND condition;

      .classOne .classTwo {}

This is an OR condition;

      .classTwo {} (could be .classOne, .classTwo {} )

This is a syntax error and will be ignored;

      .classOne.classTwo {}

Do I have this correct?

1 Answer

Seth Kroger
Seth Kroger
56,409 Points

You're correct on the second, it will select either class.

.class1, .class2 {}

<div class="class1">Selects this</div>
<div class="class2">as well as this</div>

Your first I'd call WITHIN or INSIDE, because the element with .class2 has to be a decedent, or nested within, the element with .class1.

.class1 .class2 {}

<div class="class1">
   doesn't select this
   <div class="class2">Selects this inside</div>

And the third is actually AND, not a syntax error. It will select an element with that has both classes together.

.class1.class2 {}

<div class="class1">Doesn't select this</div>
<div class="class2">or this either</div>
<div class="class1 class2">It does select this.</div>

Thanks for the clarification. I knew I. Was circling the distinctions but missed it with one and three. This really helps.