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

I cannot get the opacity set in scss.

In the challenge, the directions are: "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."

The CSS code that I think should work (but doesn't so I'm obviously out in the bush somewhere) is this:

/* Write your SCSS code below. */
p {
  a {
    color: red; 
    > a {
    color: blue;
    }
    & a .hover {
      opacity: 0.5;
      }
    }
  }

However, when I use the above code, I get this response: "Bummer! You need to set 'opacity: 0.5' for the hover pseudoclass."

It's been a while since I've written any code, but as far as I can see, I've got the correct command for the hover pseudoclass, and the opacity is correctly set.

What in the world am I doing wrong?

Thanks in advance for your help.

index.html
<!DOCTYPE html>
<html>
<head>
  <title>Sass Basics - Code Challenge</title>
  <link rel="stylesheet" type="text/css" href="page-style.css">
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <h1>Hampton's Blog</h1>
  <div class="entry">
    <h1><a href="#">Delicious Food in SF</a></h1>
    <div class="content">
      <p>
        You know what my favorite restaurant in San Francisco is? The answer is that there are so many great restaurants that I couldn't choose one. But honorable mentions include <a href="#">Mr. Chow's</a>, <a href="#">Live Sushi</a> and <a href="#">Piccino</a>. 
        <span class="link"><a href="/info.html">Read More</a></span>
      </p>
    </div>
  </div>
  <div class="entry">
    <h1><a href="#">Great Music</a></h1>
    <div class="content">
      <p>
        Here are some of my favorite bands from years past and present: Belle and Sebastian, Pixies, and Daft Punk. Listening to music allows me to focus when I'm programming. 
        <span class="link"><a href="/info.html">Read More</a></span>
      </p>
    </div>
  </div>
  <div class="footer">
    <p>
      Thanks for reading my blog!  Be sure to check out my <a href="#">other articles</a>.
    </p>
  </div>
</body>
</html>
style.scss
/* Write your SCSS code below. */

It needs to be this:

/* Write your SCSS code below. */
p {
  a {
    color: red; 
    > a {
    color: blue;
    }
    &:hover {
      opacity: 0.5;
      }
    }
  }

you have & a .hover which would target children of a descendant anchor with the literal class of 'hover'. When using pseudo classes in Sass in a nested selector use &: -- or -- Ampersand , colon -- in English.

1 Answer

Hi Steven,

This was a bit tricky for me at first as well.

on hover, all direct children have an opacity of 0.5

You already have a selector targeting all direct children. Within that selection, use the ampersand to create a nested selector that selects all direct children on hover.

If this doesn't help, let me know and I'll show you the working answer.

Best Regards

thanks for your help. I really didn't understand your reply, but Ben helped with an almost right answer.

Sorry for the confusion - it's a struggle to refrain from providing a direct answer over trying to explain how to arrive at the answer. I recommend watching some of the videos again. Sass Basics is one of my favorites and felt Hampton did a good job teaching the material.

Here it is, in code, what I was trying to explain:

/* Write your SCSS code below. */
p {
  a {
    color: red;
  }
  > a {
    color: blue;
    &:hover {
      opacity: 0.5;
    }
  }
}

Cheers