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 Sass Basics (retired) Getting Started with Sass Advanced Nesting

Alex Tasioulis
Alex Tasioulis
4,950 Points

div.footer vs .footer

p {
    a {
    color: red;
    div.footer & {
    color: purple;
        } 
  }

So it only accepted this; but it wouldn't accept the same code with just ".footer" instead of "div.footer". Why do I have to specify that it's a div? We otherwise always just use the class name like ".footer".

Was this just testing that we're really precise and that we're referring to the div with a class of footer as opposed to any sort of element with a class of footer?

Chris Dziewa
Chris Dziewa
17,781 Points

Strange, I just helped someone else on this problem and it worked with or without the div. That only increases the specificity of the selector but isn't necessary. As long as you remember the space between the selector and the ampersand it should work either way.

2 Answers

Calvin Nix
Calvin Nix
43,828 Points

Bingo. They just wanted to know that you can specify a div with the class footer. But yeah, in a real life environment it would have worked just fine. It's good to know how to do this though because in huge projects you will want to be precise.

williamrossi
williamrossi
6,232 Points

Thanks for the responses, I was missing the div!