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

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

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

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

That worked for me

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!

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;
  }
}

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.

Yes! Thank you!

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

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