Skip to content

Instantly share code, notes, and snippets.

@Vlasterx
Last active November 10, 2015 11:57
Show Gist options
  • Save Vlasterx/bebe2fa598e46dc83567 to your computer and use it in GitHub Desktop.
Save Vlasterx/bebe2fa598e46dc83567 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
$width: 300; // desired grid width in px (do not enter 'px')
$fs: 18; // base font size in px (do not enter 'px')
$const: 1.61803398874; // Line height constant
$fsconst: 1.165; // Font size growth constant
// DO NOT CHANGE ANYTHING BELOW
// ----------------------------
@function power ($x, $n) {
$ret: 1;
@if $n >= 0 {
@for $i from 1 through $n {
$ret: $ret * $x;
}
} @else {
@for $i from $n to 0 {
$ret: $ret / $x;
}
}
@return $ret;
}
@function nearestEven($number) {
$even: round($number);
$test: $even % 2;
// Number is not even, return next even number
@if ($even % 2 != 0) {
@return ($even + 1);
}
// Number is even - return it
@return $even;
}
$lh: $fs * $const;
@function calcMediaWidth($width, $fontSize, $constantLineHeight) {
$calcLineHeight: nearestEven(heightBaseline($fontSize, $fontSize, $const));
$calcWidth: floor($width / $calcLineHeight);
@if ($calcWidth > $width) {
@return ($calcWidth - 1);
}
@return $calcWidth;
}
@function heightBaseline($sizePx, $basePx, $baseRatio) {
$calcBaseline: round($basePx * $baseRatio); // $unit is rounded as well
@return nearestEven((floor($sizePx / $calcBaseline) + 1) * $calcBaseline);
}
/* Grid result calculation */
$unit: heightBaseline($fs, $fs, $const) * 1px;
$grids: calcMediaWidth($width, $fs, $const);
@print {
base-font-size: $fs * 1px;
constant: $const;
line-height: $unit;
grid-max-columns: $grids;
desired-grid-width: $width * 1px;
optimal-grid-width: $unit * $grids;
/******************
Basic font sizes
******************/
p: $fs * 1px;
h6: round($fs * power($fsconst, 1)) * 1px;
h5: round($fs * power($fsconst, 2)) * 1px;
h4: round($fs * power($fsconst, 3)) * 1px;
h3: round($fs * power($fsconst, 4)) * 1px;
h2: round($fs * power($fsconst, 5)) * 1px;
h1: round($fs * power($fsconst, 6)) * 1px;
}
/* Grid result calculation */
@print {
base-font-size: 18px;
constant: 1.61803;
line-height: 30px;
grid-max-columns: 10;
desired-grid-width: 300px;
optimal-grid-width: 300px;
/******************
Basic font sizes
******************/
p: 18px;
h6: 21px;
h5: 24px;
h4: 28px;
h3: 33px;
h2: 39px;
h1: 45px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment