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

Steve Leichman
Steve Leichman
7,008 Points

Ampersand Post-Selector - Help Please

I've been working on this and I can't figure out what's wrong. The direction is 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's what I have:

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

Can someone please tell me what I'm doing wrong? I'm sure it's something small and stupid.

Thank you.

6 Answers

Branko Veljkovic
Branko Veljkovic
6,684 Points

here it is: p { a {color:red;}

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

That worked for me

Guy Noda-Bailey
Guy Noda-Bailey
18,837 Points

Thanks Branko,

I just wanted to reformat your answer so that it would be a bit easier to figure out why it works. ;)

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

aaaah!

erick Hernandez
erick Hernandez
7,060 Points

i realize this post is old but just thought id put this here just in case someone stumbles upon for help. Just have to write this outside your previous 'P' tag nested code.

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

// add outside of previous code

a{
  div.footer &{
    color: purple;
  }
}
Steve Leichman
Steve Leichman
7,008 Points

Thanks, Branko. I tried your suggestion but unfortunately it didn't work. I feel like I've tried all variations of '''.footer &''' and '''&.footer''' in more or less every spot, but with no success. This is making me nuts.

Out side the tag p a { div.footer & { color:purple; } }

Branko Veljkovic
Branko Veljkovic
6,684 Points

try putting ampersand (&) character before class, like: ''' p{ a{ color:red; &.footer{ color: purple; } } >a{ color:blue; &:hover{ opacity:0.5; } } } '''