Advertisement
Guest User

Linearly Scale font-size with CSS clamp() Based on the Viewport

a guest
Sep 22nd, 2022
1,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | Source Code | 0 0
  1. @use "sass:math";
  2.  
  3. @function betterClamp($minSize, $maxSize, $minWidth: 1024, $maxWidth: 1920) {
  4. // source: https://css-tricks.com/linearly-scale-font-size-with-css-clamp-based-on-the-viewport/
  5. // convert to rem
  6. $minSize: math.div($minSize, 16);
  7. $maxSize: math.div($maxSize, 16);
  8. $maxWidth: math.div($maxWidth, 16);
  9. $minWidth: math.div($minWidth, 16);
  10. // do calculations
  11. $slope: math.div(($maxSize - $minSize), ($maxWidth - $minWidth));
  12. $yAxisIntersection: -$minWidth * $slope + $minSize;
  13. // output as rem
  14. $minSize: $minSize * 1rem;
  15. $maxSize: $maxSize * 1rem;
  16. @return clamp(
  17. #{$minSize},
  18. #{$yAxisIntersection * 1rem} + #{$slope * 100vw},
  19. #{$maxSize}
  20. );
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement