Skip to content

Instantly share code, notes, and snippets.

@krambuhl
Last active December 21, 2015 09:28
Show Gist options
  • Save krambuhl/6284823 to your computer and use it in GitHub Desktop.
Save krambuhl/6284823 to your computer and use it in GitHub Desktop.
Sass responsive grid implimentation
$grid-max: 12;
$grid-column: 80px;
$grid-gutter: 0px;
@function gridw ($span: $grid-max, $offset: 0px) {
@return ($grid-column * $span) + ($grid-gutter * ($span - 1)) + $offset;
}
@mixin grid ($span: $grid-max, $offset: 0px) {
width: gridw($span, $offset);
}
@mixin grid-respond ($min: -1, $max: -1, $media: "screen") {
$grid: null;
@if $min != -1 and $max != -1 {
$grid: "only " + $media + " and (min-width: " + gridw($min) + ") and (max-width: " + (gridw($max) - 1) + ")";
} @else if $min == -1 and $max != -1 {
$grid: "only " + $media + " and (max-width: " + (gridw($max) - 1) + ")";
} @else if $min != -1 and $max == -1 {
$grid: "only " + $media + " and (min-width: " + gridw($min) + ")";
} @else {
$grid: "only " + $media;
}
@media #{$grid} {
@content;
};
}
@krambuhl
Copy link
Author

krambuhl commented Mar 2, 2014

usage:

@include grid-respond(0, 6) { 
    body { background: blue; }
}

@include grid-respond(6, 9) { 
    body { background: red; }
}

@include grid-respond(9, 12) {
    body { background: pink; }
}

@include grid-respond(12) {
    body { background: green; }
}

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