Created
November 15, 2013 00:59
-
-
Save elisechant/7477377 to your computer and use it in GitHub Desktop.
SASS Type Coercion
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
// Strip units from any value | |
// | |
@function strip-units($number) { | |
@return $number / ($number * 0 + 1); | |
} | |
// Convert pixels to ems | |
// $pxval may have units or be unitless | |
// eg. for a relational value of 12px write em(12) when the parent is 16px | |
// if the parent is another value say 24px write em(12, 24) | |
@function em($pxval, $context: $base) { | |
@return (strip-units($pxval) / $context) * 1em; | |
} | |
// Convert em to px | |
// $emval may have units or be unitless | |
@function px($emval, $context: $base){ | |
@return (strip-units($emval) * $context) +0px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment