Created
August 4, 2014 09:33
-
-
Save crazyrohila/602376ad5f45de5fa362 to your computer and use it in GitHub Desktop.
Px to Rem
This file contains hidden or 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
// ---- | |
// Sass (v3.3.10) | |
// Compass (v1.0.0.alpha.20) | |
// ---- | |
@mixin x-rem($property, $values) { | |
$base-font-size: 10px; | |
$px-values: (); | |
$rem-values: (); | |
@each $value in $values { | |
@if $value == 0 or $value == 0px { | |
$px-values: join($px-values, 0); | |
$rem-values: join($rem-values, 0); | |
} @else if type-of($value) == number and not unitless($value) and (unit($value) == px) { | |
$new-rem-value: $value / $base-font-size; | |
$px-values: join($px-values, round($value)); | |
$rem-values: join($rem-values, #{$new-rem-value}rem); | |
} @else { | |
$px-values: join($px-values, round($value * $base-font-size)); | |
$rem-values: join($rem-values, #{$value}rem); | |
} | |
} | |
#{$property}: $px-values; | |
#{$property}: $rem-values; | |
} | |
.test { | |
@include x-rem(font-size, 20px); | |
} |
This file contains hidden or 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
.test { | |
font-size: 20px; | |
font-size: 2rem; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment