Last active
November 19, 2026 14:11
-
-
Save mfd/4e933389f4a74bf9f764700dc2c37d29 to your computer and use it in GitHub Desktop.
font clamp
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
| // https://www.bronco.co.uk/our-ideas/creating-a-clamp-fallback-function-in-sass-scss/ | |
| @mixin clamp( | |
| $property, | |
| $min-size, | |
| $scaler, | |
| $max-size, | |
| $min-size-left: false, | |
| $scaler-left: false, | |
| $max-size-left: false | |
| ) { | |
| @if $min-size-left == false { | |
| #{$property}: $max-size; | |
| #{$property}: #{'min(max(#{$min-size}, #{$scaler}), #{$max-size})'}; | |
| #{$property}: clamp(#{$min-size}, #{$scaler}, #{$max-size}); | |
| } @else if $min-size-left == 0 or $min-size-left == auto { | |
| #{$property}: $max-size $min-size-left; | |
| #{$property}: #{'min(max(#{$min-size}, #{$scaler}), #{$max-size})'} | |
| $min-size-left; | |
| #{$property}: clamp(#{$min-size}, #{$scaler}, #{$max-size}) $min-size-left; | |
| } @else { | |
| #{$property}: $max-size $min-size-left; | |
| #{$property}: #{'min(max(#{$min-size}, #{$scaler}), #{$max-size})'} | |
| #{'min(max(#{$min-size-left}, #{$scaler-left}), #{$max-size-left})'}; | |
| #{$property}: clamp(#{$min-size}, #{$scaler}, #{$max-size}) | |
| clamp(#{$min-size-left}, #{$scaler-left}, #{$max-size-left}); | |
| } | |
| } | |
| @mixin liquid($property, $min, $max) { | |
| $scaler: #{strip-unit($max) * 100 / strip-unit($content-width) + 'vw'}; | |
| @include clamp($property, $min, $scaler, $max); | |
| } | |
| @function strip-unit($number) { | |
| @if type-of($number) == 'number' and not unitless($number) { | |
| @return $number / ($number * 0 + 1); | |
| } | |
| @return $number; | |
| } | |
| $content-width: 1440px; | |
| .panel { | |
| @include liquid('font-size', 14px, 18px); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment