Last active
November 7, 2017 20:08
-
-
Save npostulart/1bc031537241d54bafc7 to your computer and use it in GitHub Desktop.
REM Mixin for CSS Attributes
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.14) | |
// ---- | |
@function parseInt($n) { | |
@return $n / ($n * 0 + 1); | |
} | |
@mixin rem($property, $values) { | |
$px : (); | |
$rem: (); | |
@each $value in $values { | |
@if $value == 0 or $value == auto { | |
@if $value == 0 { | |
$value: parseInt($value); | |
} | |
$px: append($px , $value); | |
$rem: append($rem, $value); | |
} @else { | |
$unit: unit($value); | |
$val: parseInt($value); | |
@if $val == 0 { | |
$px: append($px , $val); | |
$rem: append($rem, $val); | |
} @else { | |
@if $unit == "px" { | |
$px: append($px, $value); | |
$rem: append($rem, ($val / 10 + rem)); | |
} | |
@if $unit == "rem" { | |
$px: append($px, ($val * 10 + px)); | |
$rem: append($rem, $value); | |
} | |
} | |
} | |
} | |
@if $px == $rem { | |
#{$property}: $px; | |
} @else { | |
#{$property}: $px; | |
#{$property}: $rem; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment