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 Improve Your Workflow with Sass Write Nested Selectors

Kayla Pasciullo
seal-mask
.a{fill-rule:evenodd;}techdegree
Kayla Pasciullo
Front End Web Development Techdegree Student 8,325 Points

creating a nested selector in SASS with ampersand

Ive been stuck on this question googling for an answer with no success for an hour :(

heres the question: use the & to create a nested selector .icn-success and give it the color green

ive tried

.icn { font:size: 1.25em &.icn-success { color:green; } }

also tried & icn-success &-icn.success &--icn.sucess .icn-success &

please help !!! TIA

style.scss
.banner {
  padding: 1em;
  background-color: lightgrey;
 .button {
font-size: 1.5em;
}
}

.icn {
font-size: 1.25em;
&.icn-success {
color: green;
}
}

1 Answer

Blake Larson
Blake Larson
13,014 Points

You want to just continue to concat starting with the parent class.

&-success

In this example the & = .icn

To add additional examples of this using BEM

<div class="block">
  <span class="block__element"></span>
  <span class="block__element block__element--modifier"></span>
</div>
.block {
 position: relative;

 &__element {
   position: absolute;
   top: 0;
   left: 0;

   &--modifier {
     left: 50px;
   }
 }
}