有人可以解释为什么这段代码不起作用:
@red-1:#ff0000;
@red-2:#990000;
@blue-1:#000ff;
@blue-2:#00099;
.setTheme(@theme){
@color-1:~"@{@{theme}-1}";
@color-2:fade(~"@{@{theme}-2}", 10%); //doesn't work
body.@{theme} .button{
background:@color-1;
color:@color-2;
}
}
.setTheme(~"red");
感谢;
答案 0 :(得分:3)
颜色函数与此that has been submitted有关。
不要尝试在一个字符串中进行两次调用。将变量值设置为内部变量。然后在使用它们时,直接使用@@
语法。像这样:
@red-1:#ff0000;
@red-2:#990000;
@blue-1:#000ff;
@blue-2:#00099;
.setTheme(@theme){
@color-1:~"@{theme}-1";
@color-2:~"@{theme}-2";
@color-2faded: fade(@@color-2, 10%);
body.@{theme} .button{
background:@@color-1;
color:@color-2faded;
}
}
.setTheme(~"red");
或没有额外的变量:
.setTheme(@theme){
@color-1:~"@{theme}-1";
@color-2:~"@{theme}-2";
body.@{theme} .button{
background:@@color-1;
color: fade(@@color-2, 10%);
}
}
答案 1 :(得分:0)
您还可以尝试使用“颜色”功能将字符串转换为颜色
@color: '#ccc';
background: color(@color);
但是,是的,它不像你的情况那样适用于多变量。 导致 #NNNNaNNaN