Created
May 31, 2018 17:35
-
-
Save casprine/a92560853016f1bfaea729de3a8149a7 to your computer and use it in GitHub Desktop.
Sass mixins to convert px to em
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
$base: 15; | |
@function em($pixels, $context: $base) { | |
@if (unitless($pixels)) { | |
$pixels: $pixels * 1px; | |
} | |
@if (unitless($context)) { | |
$context: $context * 1px; | |
} | |
@return $pixels / $context * 1em; | |
} | |
//Usage | |
h1{ | |
font-size: em(15); | |
//returns 0.9375rem | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment