Skip to content

Instantly share code, notes, and snippets.

@johnny5th
Last active February 1, 2016 21:04
Show Gist options
  • Save johnny5th/52bee02773d324bbbeab to your computer and use it in GitHub Desktop.
Save johnny5th/52bee02773d324bbbeab to your computer and use it in GitHub Desktop.
@function em($px, $context-or-rem: strip_unit($base-font-size)) {
@if($context-or-rem == true) {
@return $px / strip_unit($base-font-size) * 1rem;
} @else {
@return $px / $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