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 Modular CSS with Sass Sass Grid System Sass Grid System Challenge

First, use a @for directive to write a loop that iterates through each column defined in the $cols variable, starting fr

First, use a @for directive to write a loop that iterates through each column defined in the $cols variable, starting from 1.

Can someone help me

style.scss
div {
  background-color: green;
}

$cols    : 10;
$width   : 50px;
$gutter  : 15px;
$context : ($width * $cols) + ($gutter * ($cols - 1));

@for $i from 1 through 8 {
    $width: percentage{1 / $i}
}
}
    .col-#{$i} {
        width: $width;
    }
}

1 Answer

Damien Watson
Damien Watson
27,419 Points

Hi Michael,

I don't like giving the complete answer that people can cut and paste and not learn anything, but I will go through each step to explain it and break it down. Hopefully this helps you understand.

The first step says to loop from 1 to $cols.

@for $i from 1 through $cols {
}

The second step to define '.grid__col--' with $i. This requires wrapping in #{}

@for $i from 1 through $cols {
  .grid__col--#{$i} {
  }
}

The third step requires you to define a '$target' variable and you then copy and paste from the question. Then you apply to the width a percentage of the two:

@for $i from 1 through $cols {
  .grid__col--#{$i} {
    $target: ($width * $i) + ($gutter * ($i - 1));
    width: percentage($target / $context)
  }
}

Note: I found the same page you did on google, but was able to jimmy it together for this result. Hope this is gives you a help in future challenges.

Thank you very much Damien Watson

Damien Watson
Damien Watson
27,419 Points

You're welcome... I learn't something from helping out ;)

Matthew McQuain
Matthew McQuain
14,184 Points

I'm from the future. The year is 2020. Things are terrible. A bag of Cheetos has taken over our government, aliens are real, people won't wear a mask because of insane reasons, even though there is a worldwide pandemic going on. Canada won't let us in! Kanye West is running for president. And yet, in the midst of all of that, this answer remains very helpful. Thanks mate!