LESS-在字符串中使用第n个子变量

LESS-在字符串中使用第n个子变量,less,css-selectors,Less,Css Selectors,肯定有办法用更少的时间重写以下内容 #bg-slider{ li:nth-child(1){ background:url('../images/bg1.jpg'); } li:nth-child(2){ background:url('../images/bg2.jpg'); } li:nth-child(3){ background:url('../images/bg3.jpg'); } } 我试过: .bg-image (@slide) { backg

肯定有办法用更少的时间重写以下内容

#bg-slider{

li:nth-child(1){
    background:url('../images/bg1.jpg');
}

li:nth-child(2){
    background:url('../images/bg2.jpg');
}

li:nth-child(3){
    background:url('../images/bg3.jpg');
}

}
我试过:

.bg-image (@slide) {
  background:url('../images/bg@{slide}.jpg');
}

#bg-slider{
li:nth-child(n){
    .bg-image(n);
}
}

但这只给了所有李的“../images/bgn.jpg”。

seven Phase max的答案是完整的。但是如果你像我一样,正在寻找更通用的东西,这可能会有所帮助:
.applyToCol(@colNum…:nth child(0n+@{colNum})
#bg-slider {
    li {
        .bkg(1);
        .bkg(2);
        .bkg(3);
    }

    .bkg(@i) {
        &:nth-child(@{i}) {
            background: url('../images/bg@{i}.jpg');
        }
    }
}