[英]Use mixin argument to create class name in LESS
I'm trying to create a simple mixin in LESS for different colors I'll use for a website. 我正在尝试在LESS中创建一个简单的mixin,用于我将用于网站的不同颜色。
What i want is use mixin
argument
as a part of class name as well. 我想要的是使用mixin
argument
作为类名的一部分。
@green: #5FBEAA; // my color variable
.text-color(@color) {
.text-{@color} {
color: @color;
}
}
.text-color(@green);
The output i'm getting is: 我得到的输出是:
.text-#5FBEAA {
color:#5FBEAA
}
What I want is: 我想要的是:
.text-green {
color:#5FBEAA
}
I think I have the solution using Variable Names . 我想我有使用变量名称的解决方案。
Less 减
@green: #5FBEAA;
.text-color(@colorname) {
@color: ~"@{colorname}";
.text-@{color}{
color: @@color;
}
}
.text-color(green);
Output 产量
.text-green {
color: #5FBEAA;
}
I don't think its possible. 我认为不可能。 The closest solution for this will be using an additional variable. 最接近的解决方案是使用额外的变量。
@green: #5FBEAA;
.text-color(@name,@color) {
.text-@{name} {
color: @color;
}
}
.text-color(green,@green);
This will compile to 这将编译为
.text-green {
color: #5FBEAA;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.