Created
June 19, 2012 14:48
-
-
Save elundmark/2954614 to your computer and use it in GitHub Desktop.
pixels to em's sass function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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