I have a one function to calculate all the possible widths
plus the margins
for the gutters.
In this same function, the grid extensions such as the pull
, push
and offset
functions are also calculated.
@function calculate-one-column() {
$a: 100%;
@if ($gutter-width-px > 0px) {
$a: ($a - ($gutter-width-procent * ($column-count - 1)));
}
@return $a / $column-count;
}
@function calculate-each-gutter() {
@if ($gutter-width-px > 0px) {
@return $gutter-width-procent;
}
@return 0;
}
@function calculate-function($function, $size, $first-child: false, $responsive: false) {
$each-column: calculate-one-column() * $size;
$each-gutter: calculate-each-gutter() * ($size - 1);
@if ($function == 'size') {
@return $each-column + $each-gutter;
} @else if ($function == 'offset' and $first-child == false) and ($responsive == false) {
@return $each-column + $each-gutter + ($gutter-width-procent * 1.5);
} @else if ($function == 'push' or $function == 'pull') and ($responsive == false) or ($function == 'offset' and $first-child == true) {
@return $each-column + $each-gutter + $gutter-width-procent;
} @else if($function == 'offset' or 'push' or 'pull') and ($responsive == true) {
@return auto !important;
}
}
The calculate-function
@function
is getting called by this piece of code:
@mixin make-grid-sizes() {
@for $index from 1 through $column-count {
&.#{$column-size}#{$index} {
@include calculate-property('width', $index);
}
}
}
All of these functions are getting hold together with these variables:
$column-count: 12;
$row-max-width: 1024px;
$gutter-width-px: 15px !default;
$gutter-width-procent: percentage($gutter-width-px / $row-max-width);
The code works perfectly, but in my opinion it looks very messy.