-
-
Save hawkz/5055085 to your computer and use it in GitHub Desktop.
Quick modification for multiple values - not the most concise, but this is being compiled pre-upload...
This file contains hidden or 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'; }())`; | |
} | |
.x-rem (@property, @v1, @v2) { | |
@px-v1: @v1 * @main-font-size; | |
@px-v2: @v2 * @main-font-size; | |
-: ~`(function () { return ';@{property}: @{px-v1} @{px-v2}'; }())`; | |
-: ~`(function () { return ';@{property}: @{v1}rem @{v2}rem'; }())`; | |
} | |
.x-rem (@property, @v1, @v2, @v3) { | |
@px-v1: @v1 * @main-font-size; | |
@px-v2: @v2 * @main-font-size; | |
@px-v3: @v3 * @main-font-size; | |
-: ~`(function () { return ';@{property}: @{px-v1} @{px-v2} @{px-v3}'; }())`; | |
-: ~`(function () { return ';@{property}: @{v1}rem @{v2}rem @{v3}rem'; }())`; | |
} | |
.x-rem (@property, @v1, @v2, @v3, @v4) { | |
@px-v1: @v1 * @main-font-size; | |
@px-v2: @v2 * @main-font-size; | |
@px-v3: @v3 * @main-font-size; | |
@px-v4: @v4 * @main-font-size; | |
-: ~`(function () { return ';@{property}: @{px-v1} @{px-v2} @{px-v3} @{px-v4}'; }())`; | |
-: ~`(function () { return ';@{property}: @{v1}rem @{v2}rem @{v3}rem @{v4}rem'; }())`; | |
} | |
.some-class { | |
.x-rem(font-size, 1.4); | |
.x-rem(margin, 1.4, 0, 2, 2.3); | |
} |
This file contains hidden or 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
Thank you! The best example of implementation, from what I have seen previously