Skip to content

Instantly share code, notes, and snippets.

@drublic
Last active March 28, 2020 23:57
Show Gist options
  • Save drublic/4374738 to your computer and use it in GitHub Desktop.
Save drublic/4374738 to your computer and use it in GitHub Desktop.
Fallback rem-mixin in Sass and LESS
@main-font-size: 16px;
.x-rem (@property, @value) {
// This is a workaround, inspired by https://github.com/borodean/less-properties
@px-fallback: @value * @main-font-size;
-: ~`(function () { return ';@{property}: @{px-fallback}'; }())`;
-: ~`(function () { return ';@{property}: @{value}rem'; }())`;
}
.some-class {
.x-rem(font-size, 1.4);
}
$main-font-size: 16px;
@mixin x-rem ($property, $value) {
#{$property}: $value * $main-font-size;
#{$property}: #{$value}rem;
}
.some-class {
@include x-rem(font-size, 1.4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment