Created
August 14, 2020 19:38
-
-
Save juanigaray/90ffe032ca9cea07cf6787a051de9e86 to your computer and use it in GitHub Desktop.
Line spacing in Sass css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The line-height value doesn't only define the distance between different lines | |
* but also distances the lines from everything around them. | |
* This mixin allows one to distance lines in a text while keeping the distance between a | |
* text and its surrounding elements constant. | |
* Assumes $line-height >= 1 | |
*/ | |
@mixin line-spacing($line-height: 1) { | |
line-height: $line-height; | |
// Negative margin to compensate for line-height pushing the first line downward / the last line upward | |
$compensation-margin: ($line-height - 1) / -2; | |
&:first-child { | |
margin-top: $compensation-margin; | |
} | |
&:last-child { | |
margin-bottom: $compensation-margin; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment