Last active
August 29, 2015 13:56
-
-
Save jonathan-fielding/8912560 to your computer and use it in GitHub Desktop.
Rem Calculator with 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
@mixin rem($property, $px-values) { | |
// Convert the baseline into rems | |
$baseline-rem: $font-size-base / 1rem * 1; | |
// Print the first line in pixel values | |
#{$property}: $px-values; | |
// If there is only one (numeric) value, return the property/value line for it. | |
@if type-of($px-values) == "number" { | |
#{$property}: $px-values / $baseline-rem; | |
} | |
@else { | |
// Create an empty list that we can dump values into | |
$rem-values: (); | |
@each $value in $px-values { | |
// If the value is zero or not a number, return it | |
@if $value == 0 or type-of( $value ) != "number" { | |
$rem-values: append($rem-values, $value); } | |
@else { | |
$rem-values: append($rem-values, $value / $baseline-rem); } } | |
// Return the property and its list of converted values | |
#{$property}: $rem-values; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage @include rem('font-size',14px);