Created
March 20, 2014 23:29
-
-
Save marciobarrios/9676288 to your computer and use it in GitHub Desktop.
px/rem mixin, from http://hugogiraudel.com/2013/03/18/ultimate-rem-mixin/
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
html { | |
font-size: 62.5%; /* 1 */ | |
} | |
@function parseInt($n) { /* 2 */ | |
@return $n / ($n * 0 + 1); | |
} | |
@mixin rem($property, $values) { | |
$px : (); /* 3 */ | |
$rem: (); /* 3 */ | |
@each $value in $values { /* 4 */ | |
@if $value == 0 or $value == auto { /* 5 */ | |
$px : append($px , $value); | |
$rem: append($rem, $value); | |
} | |
@else { | |
$unit: unit($value); /* 6 */ | |
$val: parseInt($value); /* 6 */ | |
@if $unit == "px" { /* 7 */ | |
$px : append($px, $value); | |
$rem: append($rem, ($val / 10 + rem)); | |
} | |
@if $unit == "rem" { /* 7 */ | |
$px : append($px, ($val * 10 + px)); | |
$rem: append($rem, $value); | |
} | |
} | |
} | |
@if $px == $rem { /* 8 */ | |
#{$property}: $px; /* 9 */ | |
} @else { | |
#{$property}: $px; /* 9 */ | |
#{$property}: $rem; /* 9 */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment