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

Richard Nash
Richard Nash
24,862 Points

What am i missing here? (SASS Basics Challenge)

I think that i have done this correctly and the preview is correct, but it keeps saying I'm not quite right, and asking me to include the ampersand, which I clearly have. Please help... thank you.

It's for the 4th challenge.

Here is the question:

We want to add an exception for <a> tags that are are in the <div> with a class of .footer: those links should be purple. Use the post-selector ampersand to achieve this.

Here is my code:

p {
    a {
    color: red;
            .footer & {
                  color: purple;
             }
         }
  > a {
    color: blue;
              &:hover {
                  opacity: 0.5;
              } 
    }
}

And this is the error that is giving me:

Bummer! Please use the ampersand selector following the selector for the .footer div.

It looks like I'm using the ampersand correctly to me, and it works correctly in the preview...

and how do I add tabs in the questions testa area input window... which is the window I'm trying to write this question into right now. The spacing of the code is all messed up and every time I try to add a tab it moves me to a new input field.

Thank you in advance for your help :-)

7 Answers

Hi Richard,

I'm guessing you edited your original code? I'm not seeing the missing curly brace.

They want you to be more specific with the selector, a div with the class of "footer" So use div.footer

I've found that it passes the challenge if the compiled css selector is either div.footer p a or div.footer p > a

It can be nested in either one. The instructions aren't clear to me on which one it should be.

Kevin Granger
Kevin Granger
20,332 Points

a curly brace is missing at the end, you should try to better indent your declarations ;)

Richard Nash
Richard Nash
24,862 Points

i try to indent my code really well, because it is one of the most important elements of the coding process, but it's hard when the code editor in treehouse does not indent or complete code well, plus, the text input area in this question thing does not allow for tabs and when I copied the code over it messed up all of the formatting, so this does not represent my efforts at all. It is really frustrating >_<

Richard Nash
Richard Nash
24,862 Points

shit, i see it now, i put the brace in the wrong place :-(

Richard Nash
Richard Nash
24,862 Points

fixed the curly braces but it is still wrong...

p {
    a {
    color: red;
    .footer & {
        color: purple;
    }
  }
  > a {
    color: blue;
    &:hover {
        opacity: 0.5;
    }
  }
}

dunno why at this point... and the indenting is still messed up from the copy and paste... dunno how to fix it in this question window...

Richard Nash
Richard Nash
24,862 Points

tried this one as well...

p {
    a {
    color: red;
  }
  > a {
    color: blue;
    .footer & {
            color: purple;
            &:hover {
                opacity: 0.5;
            }
    }
  }
}

sorry, shit removed...did not know it was SASS

Richard Nash
Richard Nash
24,862 Points

ok, that worked, thank you Jason :-) I don't understand why, though, as the .footer class is just as specific, I would have thought. I'll tweet Hampton :-)

div.footer p a uses 1 class and 3 type selectors. .footer p a uses 1 class and only 2 type selectors and so has a lower specificity.

.footer will select any element with a class of "footer" whereas div.footer will only select div's with a class of "footer"

In practice .footer would probably be fine. Generally you probably wouldn't see another element with a class of footer.

Richard Nash
Richard Nash
24,862 Points

hmmm... but if i have more than one div with the class .footer then this specificity would not have helped either, right? an id would give me the most specificity, i would think.

Yes, an id would.

Where div.footer would make a difference is if you had another element with a class of footer. You probably would not do this on a real project but say <footer class="footer"> Using just .footer would target both the footer and div element, whereas div.footer would specifically target the div with a class of footer and not affect the footer element with a class of footer.

This is a contrived example though. If you were going to use the new footer element in your site then you would use it consistently and wouldn't use div's anymore. Also, you wouldn't add a class of footer to it as it would be redundant.

Not sure how to answer your question and I think I'm missing what you're not understanding.

It's not so much that we have to use div.footer in the context of this code challenge it's just that the Teacher wanted you to do it this way. The instructions hint that they want you to be that specific. I'm not sure what the motivation behind it is. .footer would work perfectly fine with the html we have.

I can't think of a real world situation where you would need to do this though.

Richard Nash
Richard Nash
24,862 Points

Exactly. I would not imagine myself creating a project with more than one footer in practice, so .footer would be fine, me thinks. Always trying to keep my code light and breezy. I agree that the intent was probably to help us students focus on specificity and understanding the hierarchy of nesting in Sass, just not a very well designed example, as I don't think Hampton is as experienced a teacher as Nick, Pasan, etc... I found him quite entertaining, though :-) Anyway, finished that track, now on to front-end web development. Thank you for your help Jason :-)

You're welcome Richard.

As I thought about it more, it's probably more common to combine id and class selectors like #wrapper.about not so much combining type and class selectors like this challenge div.footer

I thought of possibly a more real world use of combining type and class selectors.

Suppose you are using the "active" class to indicate which page of your main navigation you are currently on. This class is applied to the a element. You also have a slideshow running on that page that uses the "active" class to indicate which slide is the current slide. This class is applied to the list items in the slideshow.

You can't simply use .active as your selector because then the styles will be applied to both. You could use a.active and li.active to style these elements separately.

Anyways, glad you're moving on and making progress.

Richard Nash
Richard Nash
24,862 Points

Agreed. Your example makes complete sense, as specificity is dependent upon consistent labeling and selection :-)