Skip to content

Instantly share code, notes, and snippets.

@elundmark
Created June 19, 2012 14:48
Show Gist options
  • Save elundmark/2954614 to your computer and use it in GitHub Desktop.
Save elundmark/2954614 to your computer and use it in GitHub Desktop.
pixels to em's sass function
// Your default font-size
$fs = 16;
@function px2em($target, $context: $fs) {
@return ( ( 1 / $context ) * $target )+0em;
}
// ----------
body {
font-size: 100%; // 16
}
#foo {
margin-bottom: px2em($fs * 2); // 32px -> 2em
.bar {
font-size: px2em(14); // 0.875em
margin-bottom: px2em($fs * 2, 14); // 14 given to px2em as $context, therefor -> 2.285em
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment