Created
July 11, 2013 14:52
-
-
Save jhafner/5976131 to your computer and use it in GitHub Desktop.
Simple grid in Sass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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