Generate class names with fractional numbers

前端 未结 1 984
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-16 21:02

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

相关标签:
1条回答
  • 2021-01-16 21:28

    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;
        }
    }
    

    this will generate classes from foo-0-0 to foo-3-0.

    Demo.


    When numeric conversion are not applicable use replace

    0 讨论(0)
提交回复
热议问题