Created
October 7, 2011 16:06
-
-
Save alexcabrera/1270671 to your computer and use it in GitHub Desktop.
Simple responsive grid mixins in indented sass (boiled down from Susy)
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
| // settings | |
| $std-n-cols: 12 | |
| $std-col-width: 54 | |
| $std-gutter-width: 30 | |
| // calculated constants | |
| $std-page-width: ($std-n-cols * $std-col-width) + (($std-n-cols - 1) * $std-gutter-width) | |
| @function column-width($n-cols, $col-width:$std-col-width, $gutter-width:$std-col-gutter) | |
| $column-widths: $n-cols * $col-width | |
| $gutter-widths: ($n-cols - 1) * $gutter-width | |
| @return $column-widths + $gutter-widths | |
| @function percent-width($target, $context) | |
| @return ($target / $context) * 100% | |
| @mixin column($n-cols, $context:$std-n-cols, $col-width:$std-col-width, $gutter-width:$std-gutter-width, $last:'false') | |
| float: left | |
| width: percent-width(column-width($n-cols, $col-width, $gutter-width), column-width($context, $col-width, $gutter-width)) | |
| @if $last == 'true' | |
| margin-right: 0 | |
| @else | |
| margin-right: percent-width($gutter-width, column-width($context, $col-width, $gutter-width)) | |
| @mixin prepend($n-cols, $context:$std-n-cols, $col-width:$std-col-width, $gutter-width:$std-gutter-width) | |
| padding-left: percent-width(column-width($n-cols, $col-width, $gutter-width), column-width($context, $col-width, $gutter-width)) | |
| @mixin append($n-cols, $context:$std-n-cols, $col-width:$std-col-width, $gutter-width:$std-gutter-width) | |
| padding-right: percent-width(column-width($n-cols, $col-width, $gutter-width), column-width($context, $col-width, $gutter-width)) | |
| @mixin push($n-cols, $context:$std-n-cols, $col-width:$std-col-width, $gutter-width:$std-gutter-width) | |
| margin-left: percent-width(column-width($n-cols, $col-width, $gutter-width), column-width($context, $col-width, $gutter-width)) | |
| @mixin pull($n-cols, $context:$std-n-cols, $col-width:$std-col-width, $gutter-width:$std-gutter-width) | |
| margin-left: -1 * percent-width(column-width($n-cols, $col-width, $gutter-width), column-width($context, $col-width, $gutter-width)) | |
Author
Author
Simple 3 column layout:
<div id="#lcol"> </div>
<div id="#main"> </div>
<div id="#rcol"> </div>
And the SASS
#lcol
@include column(3, 12)
#main
@include column(6, 12)
#rcol
@include column(3, 12, $last: 'true')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Make an element span 8 columns, given a context of 12 columns, prepend 1 column, append 1 column