LESS Recursive Mixin

时间:2016-04-26 18:49:33

标签: css less less-mixins

我正在尝试创建一系列模仿手机信号强度条布局的条形图,如下所示:

enter image description here

条形宽度从上到下分别为100%,75%,50%和25%

Here is a plunker with the code ...在循环mixin中分配的样式似乎没有像我预期的那样应用于条形div ...我做错了什么?

这是代码,如果你不能被plunker打扰:

的index.html:

<body>
    <div class="bars-container">
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
</body>

和style.less:

div.bars-container {
    display: inline-block;
    vertical-align: middle;
    width: 23px;
    height: 23px;
    background-color: lightgray;
    .generate-bars(@n, @i: 1) when (@i =< @n) {
        &:nth-child(@{n} - @{i} + 1) {
            width: (@i * 100% / @n);
            height: 2px;
            background-color: green;
            border: 1px solid green;
            border-radius: 5px;
            margin-bottom: 1px;
        }
        .generate-bars(@n, (@i + 1));
    }
    div {
        .generate-bars(4);
    }
}

谢谢!

0 个答案:

没有答案