Skip to content

Instantly share code, notes, and snippets.

@ChillyBwoy
Last active October 11, 2015 01:38
Show Gist options
  • Save ChillyBwoy/3782425 to your computer and use it in GitHub Desktop.
Save ChillyBwoy/3782425 to your computer and use it in GitHub Desktop.
960gs in SCSS mixin
$page_width: 850px;
@function grid_width($width, $margin, $columns) {
@return ($width - ($margin * ($columns - 1))) / $columns;
}
@mixin grid-column($columns, $prefix, $sufix, $gutter, $border_right, $border_left, $cw, $cm) {
$width: (($cw + $cm) * $columns) - $cm;
$prefix_width: ($cw + $cm) * $prefix;
$sufix_width: ($cw + $cm) * $sufix;
@if $gutter {
$sufix_width: $sufix_width + $cm;
}
display: inline-block;
margin-left: $prefix_width;
margin-right: $sufix_width;
width: $width - $border_left - $border_right;
vertical-align: top;
&:last-child {
margin-right: 0;
}
}
// (850-15*4)/5 = 158
@mixin grid-columnx5($columns: 1, $prefix: 0, $sufix: 0, $gutter: true, $border_right: 0, $border_left: 0) {
$cm: 15px;
$cw: grid_width($page_width, $cm, 5);
@include grid-column($columns, $prefix, $sufix, $gutter, $border_right, $border_left, $cw, $cm);
}
//(850-35*2)/3 = 260
@mixin grid-columnx3($columns: 1, $prefix: 0, $sufix: 0, $gutter: true, $border_right: 0, $border_left: 0) {
$cm: 20px;
$cw: grid_width($page_width, $cm, 3);
@include grid-column($columns, $prefix, $sufix, $gutter, $border_right, $border_left, $cw, $cm);
}
.columnx5-1 {
@include grid-columnx5(1);
}
.columnx5-2 {
@include grid-columnx5(2);
}
.columnx5-4 {
@include grid-columnx5(4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment