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 Advanced Sass Advanced Variables, Mixins, Functions, and Placeholders Naming Conventions

Need Help : Naming Convention Quiz Questions

Hello,

I would really appreciate it if someone could explain these quiz question solutions to me. Thanks so much in advance.

Question 1. The use of the & can be used directly before and after a compound selector. Answer : False

What is the meaning of a compond selector? And thereafter, why is the answer false?

Question 2. When you need to nest a child selector, this is how you would use the &

.block { color: orange; & .is-selected { color: red; } }

Answer : False

Why is the answer false? Doesn't the space between & and .is-selected make it the right convention to define a child selector?

1 Answer

Tom Byers
Tom Byers
13,005 Points

I think these questions are a bit misleading & pedantic. You probably know all this stuff anyway, but were just thrown by the questions. My understanding of the answers is as follows:

COMPOUND SELECTORS

<!-- Two classes on the same element -->
<div class="compound selector">
    ...
</div>

A compound selector may be used when there are multiple classes on the same element. When you style them in CSS or SCSS, you'd do it as follows:

// SCSS
.compound {
    &.selector {
        background-color: red;
    }
}

// which compiles to:
.compound.selector {
    background-color: red;
}

Note that the & on line 3 of the above code can only be used at the start of the line/before the .selector. Hence the answer to question 1 is false - you can't use the & symbol after the compound class.

PARENT & CHILD SELECTORS

<!-- Parent & Child-->
<div class="parent">
    <div class="child is-selected"></div>
</div>

The code provided in the question would style the html as follows:

.parent {
    color: orange;
    & .is-selected {
        color: red;
    }
}

//would compile to:
.parent {
    color: orange;
}
.parent .is-selected {
    color: red;
}}

The .parent .is-selected would work to style the child block, but it's technically a descendant selector, not a child selector. See this CSS-TRICKS article on Child & Sibling Selectors for more info.

To target the .is-selected child, use the child selector:

.parent {
    color: orange;
    & > .is-selected {
        color: red;
    }
}

//which compiles to

.parent {
    color: orange;
}

.parent > .is-selected {
    color: red;
}

So the answer to the question is false: the SCSS shown would style all .is-selected descendants, not the nested child element specifically. I think?!

Hope this helps.

Thank you so much for this! The answers provided are fairly accurate and I'm inclined to agree with them. It's rather unusual to see such questions , but it's been a good learn nevertheless. :)