Skip to content

Instantly share code, notes, and snippets.

@RANUX
Last active October 20, 2016 23:57
Show Gist options
  • Save RANUX/7fa0ae778dee4cb77ebd1e825e2ddb19 to your computer and use it in GitHub Desktop.
Save RANUX/7fa0ae778dee4cb77ebd1e825e2ddb19 to your computer and use it in GitHub Desktop.
Пример расчет сетки при помощи SASS
// Взято из CSS фреймворка Skeleton-Sass
// https://github.com/WhatsNewSaes/Skeleton-Sass/blob/master/scss/base/_functions.scss
//
$total-columns: 12; // всего столбоцов (можно задавать любое, но обычно 12)
$column-width: 100 / $total-columns; // ширина одного столбца относительно 100% / общее количество столбцов
$column-margin: 4%; // расстояние между столбцами
// Функция расчитывает размер столбца в процентах
// $n - номер столбца
@function grid-column-width($n) {
// расчитываем размер столбца и вычитаем отступы
@return $column-width * $n - ( $column-margin * ($total-columns - $n) / $total-columns );
}
// -------------------------
//Пример вызова функции grid-column-width():
// -------------------------
.one.column,
.one.columns { width: grid-column-width(1); }
.two.columns { width: grid-column-width(2); }
.three.columns { width: grid-column-width(3); }
.four.columns { width: grid-column-width(4); }
.five.columns { width: grid-column-width(5); }
.six.columns { width: grid-column-width(6); }
.seven.columns { width: grid-column-width(7); }
.eight.columns { width: grid-column-width(8); }
.nine.columns { width: grid-column-width(9); }
.ten.columns { width: grid-column-width(10); }
.eleven.columns { width: grid-column-width(11); }
.twelve.columns { width: 100%; margin-left: 0; }
// -------------------------
// Результат работы функции
// -------------------------
.one.column,
.one.columns { width: 4.66666666667%; }
.two.columns { width: 13.3333333333%; }
.three.columns { width: 22%; }
.four.columns { width: 30.6666666667%; }
.five.columns { width: 39.3333333333%; }
.six.columns { width: 48%; }
.seven.columns { width: 56.6666666667%; }
.eight.columns { width: 65.3333333333%; }
.nine.columns { width: 74.0%; }
.ten.columns { width: 82.6666666667%; }
.eleven.columns { width: 91.3333333333%; }
.twelve.columns { width: 100%; margin-left: 0; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment