Skip to content

Instantly share code, notes, and snippets.

@hawkz
Forked from drublic/rem-fallback.less
Last active December 14, 2015 08:08
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 hawkz/5055085 to your computer and use it in GitHub Desktop.
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...
@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);
}
$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);
}
@HelgaZhizhka
Copy link

Thank you! The best example of implementation, from what I have seen previously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment