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

Abe Layee
Abe Layee
8,378 Points

Advanced Nesting Ampersand &

I don't understand the ampersand in advanced nesting with sass. What does it do?

2 Answers

Stefan Dietz
Stefan Dietz
2,360 Points

The ampersand references the parent selector.

An example:

.product {
    background: url(img/product-default.png);

    &.type-electronics {
        background: url(img/product-electronics.png);
    }
}

&.type-electronics in this case would be compiled to the following CSS selector:

.product.type-electronics {
    background: url(img/product-electronics.png);
}

and select:

<div class="product type-electronics">
    <h2>Product example</h2>
</div>
Abe Layee
Abe Layee
8,378 Points

Aww that makes senese now:D Thank you