Skip to content

Instantly share code, notes, and snippets.

@lepittenger
Last active March 15, 2016 17:10
Show Gist options
  • Save lepittenger/2a5848803d865afe4420 to your computer and use it in GitHub Desktop.
Save lepittenger/2a5848803d865afe4420 to your computer and use it in GitHub Desktop.
calculate ems based on pixel value
/* calculate ems based on pixel value
use it like em(16px) or em(16) */
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment