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: Advanced Nesting code challenge

We want to add a style to our previous Sass code declaring that on hover, all direct <a> children have an opacity of 0.5. Use the ampersand selector to achieve this, rather than repeating the '> a' direct child selector.

I entered:

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

What am I doing wrong? I double checked the video and my syntax seems okay.

7 Answers

Michel van Essen
Michel van Essen
8,077 Points
p { 
    a { 
        color: red; 
        } 
    }    
p { 
    > a { 
        color: blue; 
        &:hover { 
            opacity: 0.5; 
            } 
        } 
    }

you forgot some curly brackets

OR BETTER

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

since you can just next >a inside the p{ rather than repeating.

I think it's because you don't need the "p" in "p > a" (since you are already nesting inside the p selector.

I appreciate everyone's help. Thank You!

Thanks for the help guys. I had the same issue with this.

Cedric Bell
Cedric Bell
10,706 Points

Thanks Michael, I was stuck on that one.

Cedric Bell
Cedric Bell
10,706 Points

Thanks Michael, I was stuck on that one.