Last active
March 28, 2020 23:57
-
-
Save drublic/4374738 to your computer and use it in GitHub Desktop.
Fallback rem-mixin in Sass and LESS
This file contains 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
@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); | |
} |
This file contains 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
$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