Skip to content

Instantly share code, notes, and snippets.

@mfd
Last active November 19, 2026 14:11
Show Gist options
  • Select an option

  • Save mfd/4e933389f4a74bf9f764700dc2c37d29 to your computer and use it in GitHub Desktop.

Select an option

Save mfd/4e933389f4a74bf9f764700dc2c37d29 to your computer and use it in GitHub Desktop.
font clamp
// 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