Skip to content

Instantly share code, notes, and snippets.

@chriseppstein
Last active July 11, 2017 01:53
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 chriseppstein/1241eee7fa6ccae7ec0c to your computer and use it in GitHub Desktop.
Save chriseppstein/1241eee7fa6ccae7ec0c to your computer and use it in GitHub Desktop.
@function apply-fn($fn, $values) {
$new-values: ();
@each $v in $values {
$new-values: append($new-values, call($fn, $v), list-separator($values));
}
@return $new-values;
}
@function rem2px($value) {
@if unit($value) == rem {
@return $value / 1rem * 16px;
} @else {
@return $value;
}
}
@mixin px-fallback($property, $values) {
$fallback: apply-fn(rem2px, $values);
@if $fallback != $values {
#{$property}: $fallback;
}
#{$property}: $values;
}
@mixin margin($value) {
@include px-fallback(margin, $value);
}
.with-fallback {
@include margin(2px 0.5rem 4px);
}
.no-fallback {
@include margin(2px 9em 4px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment