Skip to content

Instantly share code, notes, and snippets.

@pigeonfresh
Last active July 14, 2021 15:42
Show Gist options
  • Save pigeonfresh/9b64e1c2150a29f4ffbe50151bffcee6 to your computer and use it in GitHub Desktop.
Save pigeonfresh/9b64e1c2150a29f4ffbe50151bffcee6 to your computer and use it in GitHub Desktop.
Fluid SCSS function
@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