Skip to content

Instantly share code, notes, and snippets.

@arthurgouveia
Created October 29, 2013 00:50
Show Gist options
  • Save arthurgouveia/7207418 to your computer and use it in GitHub Desktop.
Save arthurgouveia/7207418 to your computer and use it in GitHub Desktop.
Simple mixin to return the property with REM units along with PX fallback.
$font-size: 16;
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}
@mixin rem($property, $values...) {
$max: length($values);
$pxValues: '';
$remValues: '';
@for $i from 1 through $max {
$value: strip-unit(nth($values, $i));
$pxValues: #{$pxValues + $value}px;
@if $i < $max {
$pxValues: #{$pxValues + " "};
}
}
@for $i from 1 through $max {
$value: strip-unit(nth($values, $i));
$remValues: #{$remValues + ($value/$font-size)}rem;
@if $i < $max {
$remValues: #{$remValues + " "};
}
}
#{$property}: $pxValues;
#{$property}: $remValues;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment