Skip to content

Instantly share code, notes, and snippets.

@rob-gordon
Last active July 13, 2020 21:31
Show Gist options
  • Save rob-gordon/3199e26aad78e8b1200d7daf258c24d5 to your computer and use it in GitHub Desktop.
Save rob-gordon/3199e26aad78e8b1200d7daf258c24d5 to your computer and use it in GitHub Desktop.
function for fluid text with clamp
/*
Before
html {
font-size: 16px;
}
@media screen and (min-width: 320px) {
html {
font-size: calc(16px + 6 * ((100vw - 320px) / 680));
}
}
@media screen and (min-width: 1000px) {
html {
font-size: 22px;
}
}
*/
function fluidClampValue(minValue, maxValue, minSize, maxSize, unit = "px") {
let intermediateValue = `calc(${minValue}${unit} + ${
maxValue - minValue
} * ((100vw - ${minSize}px) / ${maxSize - minSize}))`;
return `clamp(${minValue}${unit}, ${intermediateValue}, ${maxValue}${unit})`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment