Skip to content

Instantly share code, notes, and snippets.

@kmwalsh
Created July 19, 2021 23:04
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 kmwalsh/47f65c2d8790ff914f45cd7866c1859f to your computer and use it in GitHub Desktop.
Save kmwalsh/47f65c2d8790ff914f45cd7866c1859f to your computer and use it in GitHub Desktop.
px to em with rem support
@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