Created
July 19, 2021 23:04
-
-
Save kmwalsh/47f65c2d8790ff914f45cd7866c1859f to your computer and use it in GitHub Desktop.
px to em with rem support
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
@function em($pixels, $context: 16) { | |
@if ( comparable($pixels, 1px)) { | |
@if (unitless($pixels)) { | |
$pixels: $pixels * 1px; | |
} | |
@if (unitless($context)) { | |
$context: $context * 1px; | |
} | |
@return $pixels / $context * 1em; | |
} | |
@return $pixels; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment