Last active
August 14, 2018 16:20
-
-
Save nboliver/614a36fba72a1f95c915533a1c7a0796 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
$browser-context: 16px !default; | |
@function strip-unit($num) { | |
@return $num / ($num * 0 + 1); | |
} | |
@function convert-to-rem($value, $base-value: $browser-context) { | |
// stylelint-disable length-zero-no-unit | |
$value: strip-unit($value) / strip-unit($base-value) * 1rem; | |
@if ($value == 0rem) { $value: 0; } // Turn 0rem into 0 | |
@return $value; | |
} | |
@function rem($values, $base-value: $browser-context) { | |
$max: length($values); | |
@if $max == 1 { | |
@return convert-to-rem(nth($values, 1), $base-value); | |
} | |
$rem-values: (); | |
@for $i from 1 through $max { | |
$rem-values: append($rem-values, convert-to-rem(nth($values, $i), $base-value)); | |
} | |
@return $rem-values; | |
} | |
@function em($pixels, $context: $browser-context) { | |
@if (unitless($pixels)) { | |
$pixels: $pixels * 1px; | |
} | |
@if (unitless($context)) { | |
$context: $context * 1px; | |
} | |
@return $pixels / $context * 1em; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment