Skip to content

Instantly share code, notes, and snippets.

@jhafner
Created July 11, 2013 14:52
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 jhafner/5976131 to your computer and use it in GitHub Desktop.
Save jhafner/5976131 to your computer and use it in GitHub Desktop.
Simple grid in Sass
/* Your variables */
$nb-columns : 6;
$wrap-width : 1140px;
$column-width : 180px;
/* Calculations */
$gutter-width : ($wrap-width - $nb-columns * $column-width) / $nb-columns;
$column-pct : ($column-width / $wrap-width) * 100;
$gutter-pct : ($gutter-width / $wrap-width) * 100;
/* One single mixin */
@mixin cols($cols) {
width: $column-pct * $cols + $gutter-pct * ($cols - 1) + unquote('%');
margin-right: $gutter-pct + unquote('%');
float: left;
@media screen and (max-width: 400px) {
width: 100%;
margin-right: 0;
}
}
@mixin container {
width: 100%;
max-width: $wrap-width;
margin: 0 auto;
/* Keep the container centered. */
position: relative;
left: $gutter-pct / 2 + unquote('%');
}
* {
@include box-sizing(border-box);
}
body {
overflow: hidden;
text-align: center;
@include container;
}
.header, .footer {
padding: 1em;
margin: 1em 0;
@include cols(6);
}
.col {
padding: 1em;
@include cols(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment