Last active
July 3, 2023 00:31
-
-
Save mvsde/7c66cdde4308ed155f53f7002433254c to your computer and use it in GitHub Desktop.
Fluid typography Sass mixin
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
// 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; | |
} | |
} | |
} | |
} |
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($value) { | |
@return $value / ($value * 0 + 1); | |
} |
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
// 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