0

以下代码生成颜色类。但是,如果我想要一个类似于“黑色”和“白色”已经定义的 CSS 颜色的类,则 LESS 输出:或.c-black代替。为了简单起见,我不想在数组中的每一种颜色周围都加上引号。有没有办法将每对中的第一个数组值(这是循环内的变量)解释为字符串?.c-white.c-#000000.c-#ffffff@name.creatcolorclasses

谢谢!

@colors: black #000, white #fff, blue #008FD6, bluehover #44A1E0, grayborder #DBDBDB;

.creatcolorclasses(@iterator:1) when(@iterator <= length(@colors)) {
    @name: extract(extract(@colors, @iterator),1);
    @thecolor: extract(extract(@colors, @iterator),2);

    .c-@{name} {
        color: @thecolor !important;
    }
    .bg-@{name} {
        background-color: @thecolor !important;
    }
    .bt-@{name} {
        border-top: 1px solid @thecolor !important;
    }   
    .bb-@{name} {
        border-bottom: 1px solid @thecolor !important;
    }

    .creatcolorclasses((@iterator + 1));
}
.creatcolorclasses();
4

0 回答 0