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

Help with code challenge.

Hey guys, I am stuck on part four of this exercise. This deals with Sass. Please help me. Here is the link.

Ken Alger
Ken Alger
Treehouse Teacher

Leon;

Can you edit your post and include a link to the challenge with which you need assistance.

Thanks,

Ken

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Leon;

Task 4 of this challenge reads:

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

Let's break this down into steps, shall we?

  1. Add an exception for <a> tags. We already are targeting anchor elements, so we know our code needs to go inside the a { } section of our CSS code.
  2. We are further selecting <div> elements with a class of footer, so we need to assign properties to div.footer.
  3. The Challenge is asking us to utilize the Sass post-selector to select the anchor elements inside the div.footer, so we need to use div.footer &.
  4. Assign those elements a color of purple.

So, our CSS code snippet for this segment would look like:

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

When Sass compiles that code it will turn it into:

div.footer a {
    color: purple;
}

So the entire code for Task 4 would be:

p {
  a {
  color: red;
  }

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

Which, in case you are interested, gets compiled by Sass into:

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

As you progress through the Sass courses you will come across a resource website, if you don't know about it already, called SassMeister which I find to be very useful for working with Sass code and seeing rather immediately how it is interpreted into CSS and where, if any (generally several for me) coding errors have occurred.

Happy coding,

Ken

Harrinson Ariza
Harrinson Ariza
8,189 Points

Thanks your answer help me!

Erik McClintock
Erik McClintock
45,783 Points

Leon,

Can you post the code that you have tried and that is failing, along with an explanation of what you're having trouble with specifically?

Erik

'''html p { a { color: red; } }

p {

a { color: blue; &:hover { opacity: 0.5; & .footer div { color: purple; } } } } } '''