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 Sass Grid System

Finally, to output the width value of each column, use Sass' percentage function to return the result of $target / $context as a percentage. Use ($width * $i) + ($gutter * ($i - 1)) as the value for $target.

My code:

div {
  background-color: green;
}

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

@for $i from 1 through $cols {
    $context: context($width, $gutter, $cols, $context) !global;
    $target: ($width * $i) + ($gutter* ($i - 1));

    .grid__col--#{$i} {
        width: percentage(target / $context);
    }
}

What am I missing/doing wrong?

1 Answer

Shelby,

I see two errors in your code that are stopping it from working.

1). On the first line of the for loop in defining $context you've made a call to what looks like a context() function. That doesn't need to be there to define the $context variable.

2). When you pass in the $context variable into the percentage function you've left off the $ sign.

Here's the code that worked for me to pass this one.

div {
  background-color: green;
}

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

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

-Luke

Thank you so much!