Skip to content

Instantly share code, notes, and snippets.

@ryanburgess
Last active December 30, 2015 18:09
Show Gist options
  • Save ryanburgess/7865337 to your computer and use it in GitHub Desktop.
Save ryanburgess/7865337 to your computer and use it in GitHub Desktop.
REM Unit SASS Mixin auto automatically outputs rem units and pixel value fallback for legacy browsers.
// -----------------------------------------
// REM Units with PX fallback
// -------------------------------------------
// example: @include rem("margin", 10, 5, 10, 5);
// example: @include rem("font-size", 14);
@mixin rem($property, $values...) {
$n: length($values);
$i: 1;
$pxlist: ();
$remlist: ();
@while $i <= $n {
$itemVal: (nth($values, $i));
@if $itemVal != "auto"{
$pxlist: append($pxlist, $itemVal + px);
$remlist: append($remlist, ($itemVal / 16) + rem);
}@else{
$pxlist: append($pxlist, auto);
$remlist: append($remlist, auto);
}
$i: $i + 1;
}
#{$property}: $pxlist;
#{$property}: $remlist;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment