Last active
July 14, 2021 15:42
-
-
Save pigeonfresh/9b64e1c2150a29f4ffbe50151bffcee6 to your computer and use it in GitHub Desktop.
Fluid SCSS function
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
@function strip-unit($number) { | |
@if type-of($number) == "number" and not unitless($number) { | |
@return $number / ($number * 0 + 1); | |
} | |
@return $number; | |
} | |
@function fluid( | |
$startValue, | |
$endValue, | |
$minViewportWidth: $minVW, | |
$maxViewportWidth: $maxVW, | |
$remify: false | |
) { | |
$minValue: $startValue; | |
$maxValue: $endValue; | |
@if $endValue < $startValue { | |
$minValue: $endValue; | |
$maxValue: $startValue; | |
} | |
$additionalSize: #{strip-unit($minViewportWidth) / 100}px; | |
$startSize: remify($startValue, $remify); | |
$endSize: remify($endValue, $remify); | |
$calc: #{calc( | |
#{$startSize} + ((#{1vw} - #{$additionalSize}) * #{100 * ($endValue - $startValue) / | |
($maxViewportWidth - $minViewportWidth)}) | |
)}; | |
@return clamp(#{remify($minViewportWidth, $remify)}, #{$calc}, #{remify($maxValue, $remify)}); | |
} | |
@function fluid-font($minValue, $maxValue, $minViewportWidth: $minVW, $maxViewportWidth: $maxVW) { | |
@return fluid( | |
$minValue, | |
$maxValue, | |
$minViewportWidth: $minVW, | |
$maxViewportWidth: $maxVW, | |
$remify: true | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment