Last active
July 13, 2020 21:31
-
-
Save rob-gordon/3199e26aad78e8b1200d7daf258c24d5 to your computer and use it in GitHub Desktop.
function for fluid text with clamp
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
/* | |
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