Skip to content

Instantly share code, notes, and snippets.

@npostulart
Last active November 7, 2017 20:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npostulart/1bc031537241d54bafc7 to your computer and use it in GitHub Desktop.
Save npostulart/1bc031537241d54bafc7 to your computer and use it in GitHub Desktop.
REM Mixin for CSS Attributes
// ----
// 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