Skip to content

Instantly share code, notes, and snippets.

@ryanve
Created April 3, 2017 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanve/d26fb8377959d6df04cb0a85415fa1e2 to your computer and use it in GitHub Desktop.
Save ryanve/d26fb8377959d6df04cb0a85415fa1e2 to your computer and use it in GitHub Desktop.
px-rem mixin to generate rules in both units
$rem-size: 16px !default;
@function to-px($val) {
@if type-of($val) == number and unit($val) == rem {
@return $val * $rem-size / 1rem;
}
@return $val;
}
@function to-rem($val) {
@if type-of($val) == number and unit($val) == px {
@return $val / $rem-size * 1rem;
}
@return $val;
}
@mixin px-rem($prop, $values...) {
$px-list: ();
$rem-list: ();
@each $value in $values {
$px-list: append($px-list, to-px($value));
$rem-list: append($rem-list, to-rem($value));
}
@if ($px-list != $rem-list) {
#{$prop}: $px-list;
}
#{$prop}: $rem-list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment