Created
November 20, 2015 07:53
-
-
Save ariona/125ef89b4e48a061a2f8 to your computer and use it in GitHub Desktop.
Pixel to Em function for SASS
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
$browser-context: 16; | |
@function em($pixels, $context: $browser-context) { | |
@if (unitless($pixels)) { | |
$pixels: $pixels * 1px; | |
} | |
@if (unitless($context)) { | |
$context: $context * 1px; | |
} | |
@return $pixels / $context * 1em; | |
} | |
// Usage | |
.el{ | |
font-size: em(16); | |
font-size: em(16px); | |
padding: em(10px, 12px) em(20px, 12px); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment