Skip to content

Instantly share code, notes, and snippets.

@krstivoja
Last active November 7, 2022 14:54
Show Gist options
  • Save krstivoja/99d5f480c77bda63386040ff8c4d2cb8 to your computer and use it in GitHub Desktop.
Save krstivoja/99d5f480c77bda63386040ff8c4d2cb8 to your computer and use it in GitHub Desktop.
TypeClamp SCSS Mixin
// CSS taken from: https://websemantics.uk/tools/responsive-font-calculator/
// Set up Min - Max Viewport (without px)
$viewport-min: 800;
$viewport-max: 1680;
// TypeClamp Mixin
@mixin typeclamp ($min, $max){
font-size: clamp(
#{$min}px,
calc(1rem + (#{$max} - #{$min}) * ((100vw - #{$viewport-min}px) / (#{$viewport-max} - #{$viewport-min}))),
#{$max}px);
min-height: 0vw;
}
// Example usage
h1{
@include typeclamp(30, 120);
}
h1 {
font-size: clamp( 30px, calc(1rem + (120 - 30) * ((100vw - 800px) / (1680 - 800))), 120px);
min-height: 0vw;
}
{
"sass": {
"compiler": "dart-sass/1.32.12",
"extensions": {},
"syntax": "SCSS",
"outputStyle": "expanded"
},
"autoprefixer": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment