Skip to content

Instantly share code, notes, and snippets.

@jackarmley
Created October 25, 2015 19:33
Show Gist options
  • Save jackarmley/96b104781b3e07df4e9d to your computer and use it in GitHub Desktop.
Save jackarmley/96b104781b3e07df4e9d to your computer and use it in GitHub Desktop.
// Convert single or multiple values to em
// for a property that takes 1-4 size values
// ie: margin, padding, width, height
// @author Jack Armley
// @parm {string} @prop - property to use
// @param {interger|list} @val - value(s) to use
// @param {interger} @embase [16] - base px value of ems
.pxem(@prop,@val,@embase:16) when(length(@val) < 5){
@valuelen: length(@val);
.pxem-each(@i) when (@i > 0){
.pxem-each((@i - 1));
@indval : extract(@val,@i);
& when (@indval = 0){
@{prop}+_: @indval;
}
& when (@indval > 0){
@{prop}+_: unit((@indval / @embase),em);
}
}
.pxem-each(@valuelen);
}
p{
.pxem(margin,20 0 2 20);
.pxem(padding-top,0);
.pxem(width,20,10);
.pxem(height,60);
}
a{
.pxem(margin,60 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment