Last active
October 7, 2021 18:03
-
-
Save eloyesp/0d038cccba3ebd2428c0e17e36992405 to your computer and use it in GitHub Desktop.
Micro Responsive Font Size
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
/* Simplified Responsive Font Size | |
* Usage is @include rfs(1.2rem); | |
* Used to embed when import is not available. | |
* Based on https://github.com/twbs/rfs | |
*/ | |
@mixin rfs($value, $property: font-size) { | |
// Check value is in **rem**. | |
@if unit($value) != rem { | |
@error "`#{$value}` has not a valid unit. Use `rem`." | |
} | |
// Hardcoded config | |
$base: 1rem; | |
// Calculate the minimum value | |
$min: $base + $value / 10; | |
@if $min >= $value { | |
#{$property}: $value; | |
} @else { | |
// Calculate the variable part | |
$variable: #{ ($value * 0.9 - $base) / 0.75rem }vw; | |
#{$property}: calc(#{$min} + #{$variable}); | |
@media (min-width: 1200px) { | |
#{$property}: $value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment