Last active
August 29, 2015 14:16
-
-
Save mattjburrows/3cb25b21c09a7621cedc to your computer and use it in GitHub Desktop.
Handle REM values for supporting and non-supporting environments
This file contains 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
$ie: false; | |
$base: 16px; | |
@function strip-units($number) { | |
@return $number / ($number * 0 + 1); | |
} | |
@function convert-to-pixels($value) { | |
@if type-of($value) == 'number' { | |
$stripped: strip-units($value * $base); | |
@return #{floor($stripped)}px; | |
} @else { | |
$values: unquote(''); | |
@each $px in $value { | |
@if $px == 0 { | |
$values: append($values, $px); | |
} @else { | |
$stripped: strip-units($px * $base); | |
$values: append($values, #{floor($stripped)}px); | |
} | |
} | |
@return $values; | |
} | |
} | |
@function rem($value) { | |
@if $ie { | |
@return convert-to-pixels($value); | |
} @else { | |
@return $value; | |
} | |
} | |
.foo { | |
width: rem(1.2rem 0); | |
} |
This file contains 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
.foo { | |
width: 1.2rem 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment