Created
June 7, 2017 05:24
-
-
Save saki007ster/3c03c2f4753e17508c50655ca22f8360 to your computer and use it in GitHub Desktop.
Rem Fallback
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
@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
commented
Jun 29, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment