生成带小数的类名 [英] Generate class names with fractional numbers
本文介绍了生成带小数的类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个类,例如.rating-1-1 {} 、. rating-1-2 {},直到10.0. 1-1表示1.1.我想用-代替小数点的地方.在我当前的实现中,它生成为.rating-1.1,.rating-1.2此类,无法应用css样式.
I want to create a classes as .rating-1-1{}, .rating-1-2{}, till 10.0 . Here 1-1 means it is 1.1. Where i want to replace decimal point with - . In my current implementation it generates as .rating-1.1, .rating-1.2 this class will not work to apply the css style.
尝试输入代码
@iterations: 10;
.rate-loop (@i) when (@i > 0) {
.rate-@{i} {
width: percentage((@i / @iterations));
}
.rate-loop(@i - 0.1);
}
.rate-loop (@iterations);
推荐答案
使用简单的算术和数字函数,例如:
Use simple arithmetics and numeric functions, e.g.:
.loop(3);
.loop (@n, @j: @n) when (@j > 0) {
.loop(@j, @j - 1/10);
@i: floor(@j); // integer part
@f: floor(mod(@j, 1)*10); // fractional part
.foo-@{i}-@{f} {
width: 10% * @j;
}
}
这将生成从foo-0-0
到foo-3-0
的类.
When numeric conversion are not applicable use replace
这篇关于生成带小数的类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文