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

Steve Monsen
Steve Monsen
5,207 Points

Problem with Sass > Extending Selectors challenge

Link to challenge

Question: Style the class ".animals" to have a background of #369. Use "extend" to apply those styles to a new class, ".dogs".

My Answer:

/* Write your SCSS code below. */

%animals {
    background-color: #369;
}

.dogs { 
    @extend %animals;
}

Response: "Bummer! The .animals div should have a background-color of #369. Did you set up the .animals class correctly?"


I've tried changing the background shorthand to the more explicit background-color: to no avail. Also, the preview shows that the code works as the background for .dogs is indeed blue/#369 when refreshed.

4 Answers

This is the correct answer:

%animals { background-color: #369; }

.animals { @extend %animals; } .dogs { @extend %animals; }

Hi Steve, Why did you use % for defining you class animals? Did you try to write it .animals instead?

EDIT: ok I see now why you did it that way, quite confusing I admit. Placeholder (%animals) is used for extending, the %animals won't be rendered, but in the html file you need it for the .animals div. It would work if you want to display the .dogs div only, but in this case they want you to display the .animals div too (check it with the preview, you'll see the difference).

Steve Monsen
Steve Monsen
5,207 Points

Thanks for the clarification. Yeah, I totally ignored the html source and was thinking in terms of the old object-oriented programming examples: a dog and a fish are both animals, so we define basic characteristics and traits of animals, then extend animals w/ dogs and fish, etc.

But when you actually pay attention to the classes in the html file like you did it makes more sense :)

Steve Monsen
Steve Monsen
5,207 Points

Oh, that's right. I was getting ahead of myself and trying to use the placeholder feature w/ %. Thanks for the heads up!

Aaron Witherspoon
Aaron Witherspoon
9,911 Points

Hi, I'm having an issue with this as well... .animals { backgound-color: #369; } .dogs { @extend .animals; } I can't figure out why this is not working??

Any help is appreciated.

You mispelled "background-color". :)

Aaron Witherspoon
Aaron Witherspoon
9,911 Points

OH MAN... That's what I get for taking classes late at night.... and here I was stumped, trying to figure out why that wouldn't work.... Sheesh!

Thanks a bunch

I edited my previous answer.