Skip to content

Instantly share code, notes, and snippets.

@drewminns
Created June 16, 2016 16:17
Show Gist options
  • Save drewminns/43cbcb11c398af63959b760fd0a5f835 to your computer and use it in GitHub Desktop.
Save drewminns/43cbcb11c398af63959b760fd0a5f835 to your computer and use it in GitHub Desktop.
Grid Loop
$columns: (
small: 4,
medium: 6,
large: 12,
xl: 12
);
$gutter: 20px;
$padding: $gutter;
$breakpoints: (
small: (null, 480px), // default, no min-width. ("320" - 768px)
medium: (481px, 768px),
large: (768px, 1160px), // no max-width. Our max- container width covers that case
xl: (1160px, null)
);
@mixin columns($num, $column-num) {
float: left;
width: percentage($num / $column-num);
padding: 0 $gutter / 1.5;
}
@mixin offsetcolumns($num, $columns) {
float: left;
margin-left: percentage($num / $columns);
}
@mixin from-breakpoint($bp) {
@if ($bp == 'small') {
@content;
}
@else {
@if map-has-key($breakpoints, $bp) {
$list: map-get($breakpoints, $bp);
$bp: nth($list, 1);
}
@media screen and (min-width: #{$bp + 1}) {
@content;
}
}
}
@each $size, $count in $columns {
@for $num from 1 through $count {
@include from-breakpoint(#{$size}) {
.#{$size}-#{$num} {
@include columns($num, $count);
}
.offset-#{$size}-#{$num} {
@include offsetcolumns($num, $count);
}
}
@include at-breakpoint(#{$size}) {
.hidden-#{$size} {
display: none !important;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment