Created
October 29, 2013 00:50
-
-
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.
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
$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