Skip to content

Instantly share code, notes, and snippets.

@saki007ster
Created June 7, 2017 05:24
Show Gist options
  • Save saki007ster/3c03c2f4753e17508c50655ca22f8360 to your computer and use it in GitHub Desktop.
Save saki007ster/3c03c2f4753e17508c50655ca22f8360 to your computer and use it in GitHub Desktop.
Rem Fallback
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}
@mixin rem-fallback($property, $values...) {
$max: length($values);
$pxValues: '';
$remValues: '';
@for $i from 1 through $max {
$value: strip-unit(nth($values, $i));
$pxValues: #{$pxValues + $value*16}px;
@if $i < $max {
$pxValues: #{$pxValues + " "};
}
}
@for $i from 1 through $max {
$value: strip-unit(nth($values, $i));
$remValues: #{$remValues + $value}rem;
@if $i < $max {
$remValues: #{$remValues + " "};
}
}
#{$property}: $pxValues;
#{$property}: $remValues;
}
// So that this can be used as
//.selector {
// @include rem-fallback(margin, 10, 20, 30, 40);
//}
// to get
//.selector {
// margin: 160px 320px 480px 640px;
// margin: 10rem 20rem 30rem 40rem;
//}
@skippednote
Copy link

skippednote commented Jun 29, 2017

@mixin toRem($value) {
  font-size: $value;
  font-size: $value / 16;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment