Created
July 5, 2016 15:20
-
-
Save johnny5th/9f7c9ed6c060656343fea32f0a63d6cf to your computer and use it in GitHub Desktop.
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
// if $context is true, switch to rem | |
@function em($px, $context-or-rem: $base-font-size) { | |
@if($context-or-rem == true) { | |
@return $px / strip_unit($base-font-size) * 1rem; | |
} @else { | |
@return $px / strip_unit($context-or-rem) * 1em; | |
} | |
} | |
/// Remove the unit of a length | |
/// @param {Number} $number - Number to remove unit from | |
/// @return {Number} - Unitless number | |
@function strip_unit($number) { | |
@if type-of($number) == 'number' and not unitless($number) { | |
@return $number / ($number * 0 + 1); | |
} | |
@return $number; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment