Skip to content

Instantly share code, notes, and snippets.

@eddiemoore
Last active July 20, 2018 12:38
Show Gist options
  • Save eddiemoore/7078773 to your computer and use it in GitHub Desktop.
Save eddiemoore/7078773 to your computer and use it in GitHub Desktop.
SASS Loop to generate CSS column classes
$total-columns: 6;
$col-widths: ();
@for $i from 1 through $total-columns {
@for $j from 1 through $i {
$w: ($j/$i);
@if not index($col-widths, $w) {
.col-#{$j}-#{$i} {
width: $w * 100%;
}
$col-widths: append($col-widths, $w, comma);
}
}
}
.col-1-1 { width: 100%; }
.col-1-2 { width: 50%; }
.col-1-3 { width: 33.33333%; }
.col-2-3 { width: 66.66667%; }
.col-1-4 { width: 25%; }
.col-3-4 { width: 75%; }
.col-1-5 { width: 20%; }
.col-2-5 { width: 40%; }
.col-3-5 { width: 60%; }
.col-4-5 { width: 80%; }
.col-1-6 { width: 16.66667%; }
.col-5-6 { width: 83.33333%; }
Copy link

ghost commented Feb 27, 2018

this is not sass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment