Created
August 1, 2014 17:49
-
-
Save MichaelArestad/f55bf41b1a9c86979314 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or 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
// ---- | |
// Sass (v3.3.12) | |
// Compass (v1.0.0.alpha.21) | |
// ---- | |
// ========================================================================== | |
// em() | |
// | |
// Convert px to em in a readable fashion. | |
// ========================================================================== | |
// Examples: | |
// 1. font-size: em(14); | |
// 2. font-size: em(30/14); | |
@function em($value, $context: map-get($root-font, font-size)) { | |
@return ($value / $context * 1em); | |
} | |
// ========================================================================== | |
// Demoing em() | |
// ========================================================================== | |
// Initial sass map to set base font settings (so good) | |
$root-font:( | |
font-size: 18px, | |
); | |
// example of how to set base font size on body | |
// It's the only time you have to use the map-get | |
body { | |
font-size: map-get($root-font, font-size); | |
} | |
// Example of em usage | |
div { | |
/* padding value = 10/18 */ | |
padding: em(10px); | |
font: 400 #{em(18px)}/1.6 lato; | |
.child { | |
/* font-size value = 9/18 */ | |
font-size: em(9px); | |
} | |
} | |
// Gotchas | |
.desired { | |
font: 400 1em/1.6 lato; | |
} | |
.breaks { | |
font: 400 em(18px)/1.6 lato; | |
} | |
This file contains hidden or 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
body { | |
font-size: 18px; | |
} | |
div { | |
/* padding value = 10/18 */ | |
padding: 0.55556em; | |
font: 400 1em/1.6 lato; | |
} | |
div .child { | |
/* font-size value = 9/18 */ | |
font-size: 0.5em; | |
} | |
.desired { | |
font: 400 1em/1.6 lato; | |
} | |
.breaks { | |
font: 400 0.625em lato; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment