Skip to content

Instantly share code, notes, and snippets.

@johnny5th
Created July 5, 2016 15:20
Show Gist options
  • Save johnny5th/9f7c9ed6c060656343fea32f0a63d6cf to your computer and use it in GitHub Desktop.
Save johnny5th/9f7c9ed6c060656343fea32f0a63d6cf to your computer and use it in GitHub Desktop.
// 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