Created
December 18, 2017 07:20
-
-
Save floster/58dc6085efd2b86498f6cf5785a69c82 to your computer and use it in GitHub Desktop.
Fluid Font Size
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
@function strip-unit($number) { | |
@if type-of($number) == 'number' and not unitless($number) { | |
@return $number / ($number * 0 + 1); | |
} | |
@return $number; | |
} | |
@function calcFluidFontSize($f-min, $f-max, $w-min, $w-max, $units: px) { | |
$f-min: strip-unit($f-min); | |
$f-max: strip-unit($f-max); | |
$w-min: strip-unit($w-min); | |
$w-max: strip-unit($w-max); | |
$k: ($f-max - $f-min)/($w-max - $w-min); | |
$b: $f-min - $k * $w-min; | |
$b: $b + $units; | |
@return calc( #{$k} * 100vw + #{$b} ); | |
} | |
@mixin fluidFontSize($f-min, $f-max, $w-min, $w-max, $fallback: false) { | |
font-size: $f-min; | |
@media (min-width: $w-min) { | |
@if ($fallback) { | |
font-size: $fallback; | |
} | |
font-size: calcFluidFontSize($f-min, $f-max, $w-min, $w-max, px); | |
} | |
@media (min-width: $w-max) { | |
font-size: $f-max; | |
} | |
} | |
.fluid-font-size { | |
@include fluidFontSize(16px, 24px, 480px, 1280px, 18px); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment