LESS class name string interpolation not working

2020-02-16 03:17发布

I am currently translating my grid into LESS, but I can't seem to figure out string interpolation.

Here's helper class that is supposed to generate all my columns:

.createColumns (@colNumber+1) {}

.createColumns (@index) when (@index < @colNumber) {
    (~".col@{index}") {
         width: @baseWidth * @index;
    }

    .createColumns (@index + 1);
}

.createColumns (01);

Problem is, I get error that says something is wrong with this part (~".col@{index}").

Here's the error message:

ParseError: Unrecognised input
in grid.css on line 17, column 4:
16    .createColumns (@index) when (@index < @colNumber) {
17        (~".col@{index}") {
18            width: @baseWidth * @index;

I have checked several examples and all use same syntax, so I'm not sure what I'm missing. This was also one of my tries that resulted in an error:

.createColumns (@index) when (@index < @colNumber) {
    @class : "col"@index;
    .(@class) {
        width: @baseWidth * @index;
    }
.createColumns (@index + 1);
}

1条回答
戒情不戒烟
2楼-- · 2020-02-16 03:24

Escaped selector interpolation is deprecated in 1.4.x, use

.col@{index} {
     width: @baseWidth * @index;
}

instead.

查看更多
登录 后发表回答