Skip to content

Instantly share code, notes, and snippets.

@tommymarshall
Created September 2, 2015 17:33
Show Gist options
  • Save tommymarshall/a192900d712f45b65013 to your computer and use it in GitHub Desktop.
Save tommymarshall/a192900d712f45b65013 to your computer and use it in GitHub Desktop.
How I do a grid.
// Variables
$total-columns : 14
$grid-max-width : 1400px
$max-page-width : 1800px
$column-gutter : 0%
$column-width : (100 - $column-gutter * ($total-columns - 1)) / $total-columns
$span-real-width : round($grid-max-width * $column-width / 100%)
// Mixins
=space-span($space, $span: 1)
width: percentage($space / ($span-real-width * $span))
=offset($cols)
margin-left: $column-width * $cols + $column-gutter * $cols !important
=gutter($cols)
margin-left: $column-gutter * $cols
=span($cols, $offset: false)
float: left
@if $cols == "1/2"
width: 50%
@else if $cols == "1/3"
width: 33.333%
@else if $cols == "1/4"
width: 25%
@else
@if $offset
margin-left: $column-gutter
@else
margin-left: 0
width: $column-width * $cols + $column-gutter * ($cols - 1)
// Functions
@function col-width($cols : 1)
@return percentage(1/$total-columns) * $cols
// Classes
@for $i from 1 through $total-columns
.span-#{$i}
+span($i)
.offset-#{$i}
+offset($i)
.offset-#{$i}:not(:first-child)
margin-left: $column-width * $i + $column-gutter * ($i + 1) !important
.span-#{$total-columns}
margin-left: 0
width: 100%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment