Last active
August 29, 2015 14:16
-
-
Save codepunkt/0bb4333566c2c1723150 to your computer and use it in GitHub Desktop.
px to rem mixin
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 px-to-rem($val, $base: 16) { | |
// if it's a unitless number | |
@if type-of($val) == number and unitless($val) { | |
// don't convert 0 | |
@if $val == 0 { | |
@return 0; | |
} | |
// assume its px and convert it to rem based on $base document font-size | |
@return #{$val / $base}rem; | |
} | |
@return $val; | |
} | |
@mixin rem($property, $values...) { | |
$max: length($values); | |
$value: ''; | |
@for $i from 1 through $max { | |
$value: #{$value + px-to-rem(nth($values, $i))}; | |
@if $i < $max { | |
$value: #{$value + " "}; | |
} | |
} | |
#{$property}: $value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment