Created
May 26, 2019 16:27
-
-
Save marocas/5e0fab5ba108d481953ecc33a901f959 to your computer and use it in GitHub Desktop.
Sass Fluid Typography
This file contains hidden or 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
//- Mixin: Fluid Type | |
/// | |
/// Magic calc + vh to allow text to be fluid between minimum | |
/// and maximum breakpoints. | |
/// | |
/// @group typography | |
/// @param {variable} $min-font-size [12px] - Minimum font size | |
/// @param {variable} $max-font-size [24px] - Maximum font size | |
/// @param {variable} $lower-range [420px] - Stop scaling font smaller at this screen resolution | |
/// @param {variable} $upper-range [900px] - Stop scaling font larger at this screen resolution | |
/// @example | |
/// h1 { | |
/// @include responsive-type(20px, 48px); | |
/// } | |
/// @site https://madebymike.com.au/writing/precise-control-responsive-typography/ | |
@mixin fluid-type($min-font-size: 12px, $max-font-size: 21px, $lower-range: 420px, $upper-range: 900px) { | |
font-size: calc(#{$min-font-size} + #{(($max-font-size / ($max-font-size * 0 + 1)) - ($min-font-size / ($min-font-size * 0 + 1)))} * ( (100vw - #{$lower-range}) / #{(($upper-range / ($upper-range * 0 + 1)) - ($lower-range / ($lower-range * 0 + 1)))})); | |
@media screen and (max-width: $lower-range) { | |
font-size: $min-font-size; | |
} | |
@media screen and (min-width: $upper-range){ | |
font-size: $max-font-size; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment