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'm having a problem when it comes to adding the exception for <a> tags under the class of .footer

The error message just says that I am not positioning the ampersand correctly. I honestly just can't figure out what I'm doing wrong here.

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. */

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

4 Answers

Hey

So first: You don't need to nest it into the " > a " tree. You want to display all <a> tags in the footer div purple. Second: you need to call: div.footer & {} , not just .footer. So your code should look similar to this:

p {
  a {
    color: red;
    div.footer & {
      color: purple;
    }
  }
  > a {
    color: blue;
    &:hover {
      opacity: 0.5;
    }
   }
  } 
John McKinney
John McKinney
15,331 Points

In Sass and Less, the & is a reference to the parent selector so using it in the class of footer in your code would call it on the body tag. It should look more like this:

.footer { 
  &:before {
    color: purple;
  }
}

I tried that, and it still gave me the same error. I changed my code so that I have the .footer class nested inside of <p> and "> a", though. Wouldn't putting the ampersand behind the .footer class translate to ".footer p > a" and target any <a> that is a direct child of <p> that is in the .footer class?

My code is now this:

p { a { color: red; }

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

I've had the same issues. I needed to put div.footer & inside my a selector. This code worked for me. Originally I tried .footer & and .footer > & and they failed, although the css functioned correctly.

https://www.dropbox.com/s/nysnqwx3e2gzfqu/Screenshot%202015-09-21%2017.44.28.png