Last active
December 9, 2024 20:51
-
-
Save benabraham/0480332e60d14bb98b4c17ffb81f4f51 to your computer and use it in GitHub Desktop.
clampDimension
This file contains hidden or 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
| @use "sass:math"; | |
| @function clampDimension( | |
| $minViewportWidthPx, | |
| $minDimensionRem, | |
| $maxViewportWidthPx, | |
| $maxDimensionRem, | |
| $remSize: 16px | |
| ) { | |
| $minWidth: math.div($minViewportWidthPx, $remSize); | |
| $maxWidth: math.div($maxViewportWidthPx, $remSize); | |
| $slope: math.div( | |
| math.div($maxDimensionRem - $minDimensionRem, 1rem), | |
| $maxWidth - $minWidth | |
| ); | |
| $yAxisIntersection: -$minWidth * $slope + $minDimensionRem; | |
| @return clamp( | |
| #{$minDimensionRem}, | |
| #{$yAxisIntersection} + #{$slope * 100}vw, | |
| #{$maxDimensionRem} | |
| ); | |
| } | |
| .usage-basic { | |
| font-size: clampDimension(400px, 1rem, 1200px, 2rem); | |
| } | |
| .usage-custom-rem-size { | |
| font-size: clampDimension(400px, 1rem, 1200px, 2rem, 24px); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test at Sass playground