Skip to content

Instantly share code, notes, and snippets.

@mattjburrows
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattjburrows/3cb25b21c09a7621cedc to your computer and use it in GitHub Desktop.
Save mattjburrows/3cb25b21c09a7621cedc to your computer and use it in GitHub Desktop.
Handle REM values for supporting and non-supporting environments
$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);
}
.foo {
width: 1.2rem 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment