[英]css less mixin rem calculator without being orientated to font or something
Morning everyone i have the following mixin and i would like to transform it into a global one. 早上大家,我有以下mixin,我想将其转变为全球性的。 What i mean is without settings the margin i want to use it for font-size for example .. or for anything else that you might want to set it into rem / em units.
我的意思是没有设置边距,例如,我想将其用于字体大小..或您可能希望将其设置为rem / em单位的任何其他内容。 I'm new to less and preprocessors and i was wondering if someone from here might help me out changing the code.
我是较少接触预处理器的新手,我想知道这里是否有人可以帮助我更改代码。 thank you very much for your time.
非常感谢您的宝贵时间。
.marginSizeCalc(@sv) {
@sizeValue: unit(@sv);
@remValue: (@sizeValue / @font-size-base);
margin: unit(@sv,px);
margin: unit(@remValue,rem);
}
Found a way to solve the problem... and i think it's even better than setting margin or font or anything else inside the mixin. 找到了解决问题的方法...而且我认为这比在marginin中设置边距或字体或其他任何方法都更好。
.marginSizeCalc(@sv) {
@sizeValue: unit(@sv);
@remValue: (@sizeValue / @font-size-base);
@toRem: unit(@remValue, rem);
}
How To: 如何:
h1, h2, h3, h4, h5, h6 {
font-family: @headings-font-family;
font-weight: @headings-font-weight;
color: @headings-font-color;
margin: @remValue;
margin: @toRem;
.marginSizeCalc(@gutterWidth);
}
Update: 更新:
.marginSizeCalc(@sv, @db) {
@sizeValue: unit(@sv);
@divideBy: unit(@sv);
@remValue: (@sizeValue / @divideBy);
@toPx: unit(@remValue, px);
@toRem: unit(@remValue, rem);
}
h1, h2, h3, h4, h5, h6 {
font-family: @headings-font-family;
font-weight: @headings-font-weight;
color: @headings-font-color;
margin: @toPx;
margin: @toRem;
.marginSizeCalc(@gutterWidth, 2);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.