Skip to content

Instantly share code, notes, and snippets.

@galpratama
Forked from ariona/pxtoem-function.scss
Created November 23, 2015 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galpratama/6d9fd6db2bfee0025f5a to your computer and use it in GitHub Desktop.
Save galpratama/6d9fd6db2bfee0025f5a to your computer and use it in GitHub Desktop.
Pixel to Em function for SASS
$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