Created
May 17, 2016 08:27
-
-
Save wangqs1990/8b8f3f30385162b7fae412a558ea8de2 to your computer and use it in GitHub Desktop.
less px2rem function
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
@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