Skip to content

Instantly share code, notes, and snippets.

@jonchretien
Last active December 12, 2015 08:09
Show Gist options
  • Save jonchretien/4742128 to your computer and use it in GitHub Desktop.
Save jonchretien/4742128 to your computer and use it in GitHub Desktop.
Sass Grid Calculator
// Grid System
// -------------------------
@function calculateRowMargin($gridGutterWidth) {
@return ($gridGutterWidth * -1);
}
@function calculateColumnWidth($i, $gridColumnWidth, $gridGutterWidth) {
@return ($i * $gridColumnWidth) + (($i - 1) * $gridGutterWidth);
}
@function calculateOffsets($i, $gridColumnWidth, $gridGutterWidth) {
@return ($i * $gridColumnWidth) + (($i + 1) * $gridGutterWidth);
}
@mixin makeRow($gridGutterWidth) {
.row {
margin-left: calculateRowMargin($gridGutterWidth) + px;
}
}
@mixin makeColumns($columns, $gridColumnWidth, $gridGutterWidth) {
[class*="span"] {
float: left;
margin-left: $gridGutterWidth + px;
}
@for $i from 1 through $columns {
.span#{$i} {
width: calculateColumnWidth($i, $gridColumnWidth, $gridGutterWidth) + px
}
.offset#{$i} {
margin-left: calculateOffsets($i, $gridColumnWidth, $gridGutterWidth) + px
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment