Skip to content

Instantly share code, notes, and snippets.

@cherifGsoul
Created July 23, 2020 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherifGsoul/5058f6e9efe15f8e41de443d1788d465 to your computer and use it in GitHub Desktop.
Save cherifGsoul/5058f6e9efe15f8e41de443d1788d465 to your computer and use it in GitHub Desktop.
$base-font-size: 16px;
$base-line-height: 1.5;
$rhythm-line: round($base-font-size * $base-line-height); // in pixels
$caps-height: 0.68;
@function calculate-lines-for-size($font-size) {
// Returns unitless value
@return ceil(($font-size + 0.001) / $rhythm-line);
}
@function calculate-line-height($font-size) {
$lines-count: calculate-lines-for-size($font-size);
@return round($rhythm-line * $lines-count);
}
@function calculate-padding-top($font-size) {
$line-height: calculate-line-height($font-size);
@return ($line-height - ($font-size * $caps-height)) / 2;
}
@function calculate-margin-bottom($font-size) {
$padding-top: calculate-padding-top($font-size);
@return $rhythm-line - $padding-top;
}
@mixin vertical-rhythm($font-size: $base-font-size) {
font-size: round($font-size);
line-height: round(calculate-line-height(round($font-size)));
padding-top: round(calculate-padding-top(round($font-size)));
margin-bottom: round(calculate-margin-bottom(round($font-size)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment