Skip to content

Instantly share code, notes, and snippets.

@mvsde
Last active July 3, 2023 00:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvsde/7c66cdde4308ed155f53f7002433254c to your computer and use it in GitHub Desktop.
Save mvsde/7c66cdde4308ed155f53f7002433254c to your computer and use it in GitHub Desktop.
Fluid typography Sass mixin
// Modern browsers have support for the CSS clamp function:
// https://developer.mozilla.org/en-US/docs/Web/CSS/clamp()
// Source: https://css-tricks.com/snippets/css/fluid-typography/
@mixin fluid-type($min-font-size, $max-font-size, $min-vw: $breakpoint-min, $max-vw: $breakpoint-max) {
$u1: unit($min-vw);
$u2: unit($max-vw);
$u3: unit($min-font-size);
$u4: unit($max-font-size);
@if $u1 == $u2 and $u1 == $u3 and $u1 == $u4 {
& {
font-size: $min-font-size;
@media (min-width: $min-vw) {
font-size: calc(#{$min-font-size} + #{strip-unit($max-font-size - $min-font-size)} * ((100vw - #{$min-vw}) / #{strip-unit($max-vw - $min-vw)}));
}
@media (min-width: $max-vw) {
font-size: $max-font-size;
}
}
}
}
@function strip-unit($value) {
@return $value / ($value * 0 + 1);
}
// Adjust these to your actual min and max breakpoints
$breakpoint-min: 30rem;
$breakpoint-max: 75rem;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment