Skip to content

Instantly share code, notes, and snippets.

@casprine
Created May 31, 2018 17:35
Show Gist options
  • Save casprine/a92560853016f1bfaea729de3a8149a7 to your computer and use it in GitHub Desktop.
Save casprine/a92560853016f1bfaea729de3a8149a7 to your computer and use it in GitHub Desktop.
Sass mixins to convert px to em
$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