Skip to content

Instantly share code, notes, and snippets.

@kroyxt
Last active December 10, 2021 12:26
Show Gist options
  • Save kroyxt/b1c281a5cf4ea734e2a86cd4c724a55f to your computer and use it in GitHub Desktop.
Save kroyxt/b1c281a5cf4ea734e2a86cd4c724a55f to your computer and use it in GitHub Desktop.
Create Simple Vertical Rhythm with Sass
@use "sass:math";
@function calculateFontSize($step:0, $fontSize: 1rem) {
$ratio: 1.333;
$newFontSize: $fontSize * math.pow($ratio, $step);
@return $newFontSize;
}
@function calculateLineHeight($fontSize) {
$lineHeight: 1.5;
$maxRatio: 1.9;
$minRatio: 1.3;
$ratio: math.div($lineHeight, $fontSize);
$increment: math.div($lineHeight, 4);
$newLineHeight: $lineHeight;
@while $ratio < $minRatio {
$newLineHeight: $newLineHeight + $increment;
$ratio: math.div($newLineHeight, $fontSize);
}
@while $ratio > $maxRatio {
$newLineHeight: $newLineHeight - $increment;
$ratio: math.div($newLineHeight, $fontSize);
}
@return $newLineHeight+rem;
}
@import "_function.scss";
@mixin verticalRhythm($step: 0, $fontSize: 1rem) {
$_fontSize: calculateFontSize($step, $fontSize);
font-size: $_fontSize;
line-height: calculateLineHeight($_fontSize);
}
@import "_mixins.scss";
body {
font-size: 1rem;
line-height: 1.5;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.t1 {
@include verticalRhythm(5);
}
.t2 {
@include verticalRhythm(4);
}
.t3 {
@include verticalRhythm(3);
}
.t4 {
@include verticalRhythm(2);
}
.t5 {
@include verticalRhythm(1);
}
.t6 {
@include verticalRhythm();
}
.s1 {
@include verticalRhythm(-1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment