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) Advanced Sass Concepts Creating Loops with @for and @each

Zeller Ash
seal-mask
.a{fill-rule:evenodd;}techdegree
Zeller Ash
Front End Web Development Techdegree Student 6,361 Points

Not sure where I went wrong with this @each loop.

Going through the challenge and came up with this:

@each $color in red, blue, green {
  .red_box.#{$color} {
    background: red;
    }
  .blue_box.#{$color} {
    background: blue;
    }
  .green_bow.#{$color} {
    background: green;
    }
    }

Not sure where I went wrong, but it's saying I didn't set up the loop correctly.

1 Answer

Colin Bell
Colin Bell
29,679 Points

You want to use the $color in both the name and the background property.

@each $color in red, blue, green {
  .#{$color}_box {
    background-color: $color;
  }
}

That way, if you wanted to add more colors you would just need to add one to the list without touching the inside of the each function at all.