Skip to content

Instantly share code, notes, and snippets.

@wangqs1990
Created May 17, 2016 08:27
Show Gist options
  • Save wangqs1990/8b8f3f30385162b7fae412a558ea8de2 to your computer and use it in GitHub Desktop.
Save wangqs1990/8b8f3f30385162b7fae412a558ea8de2 to your computer and use it in GitHub Desktop.
less px2rem function
@base-font-size: 100;
.rem (@property; @values...) {
// This is a workaround, inspired by https://github.com/borodean/less-properties
@{property}: ~`(function () {
var baseFontSize=@{base-font-size};
var sizeList = @{values};
if (!Array.isArray(sizeList)) {
sizeList = [sizeList];
}
var rems = [];
for (var i = 0; i < sizeList.length; i++) {
rems.push(Math.round(sizeList[i] / baseFontSize * 1000000) / 1000000 + 'rem');
}
return rems.join(' ');
}())`;
}
.some-class {
.rem(font-size, 14);
.rem(margin, 10, 0, 10, 20)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment