Skip to content

Instantly share code, notes, and snippets.

@CodeRecipez
Last active December 15, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeRecipez/5264568 to your computer and use it in GitHub Desktop.
Save CodeRecipez/5264568 to your computer and use it in GitHub Desktop.
Sass 101 - A newb's guide: Operations range of numbers w/silent placeholders

The @for directive repeatedly outputs a set of styles. For each repetition, a counter variable is used to adjust the output. The directive has two forms: @for $var from <start> through <end> and @for $var from <start> to <end>.

The following illustrates how you can use placeholder selectors to create a series of options that don't process into CSS until extended into another selector.

$cols: 12;

@for $i from 1 through $cols {
  %grid_#{$i}of#{$cols} {
    @include grid($i, $grid_context: $cols);
  }
}

.box {
  @extend %grid_6of12;
}

Note: The grid mixin is being leveraged from the Stipe Compass extension for illustration of this exercise.

SassMeister Gist

// Stipe v0.0.5.7.4
$cols: 12;
@for $i from 1 through $cols {
%grid_#{$i}of#{$cols} {
@include grid($i, $grid_context: $cols);
}
}
.box {
@extend %grid_6of12;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment