我正在寻找LESS中的功能,以便能够更改一个变量并让它更改一堆不同的变量,以便我可以更改我的编译目标并轻松更改大量变量。
这是我正在寻找的一个例子。唯一的问题是因为我在UITableView
内重新定义了@img
它在另一个范围内。
.compile_for_if
答案 0 :(得分:1)
您可以通过在无名空间(&{...}
)中包含所有规则,然后在其范围内调用.compile_for_if
mixin来实现此目的。这会将.compile_for_if
中设置的所有变量暴露给命名空间,从而所有规则都能够访问它。 (注意:您还必须更改.compile_for_if
定义,如下所示。)
@compile_for: "endpoint1";
@img_endpoint1: "./myImg.png";
@img_endpoint2: "https://somewhere.com/myImg.png";
@img: "./default.png";
/* Added another set of conditional variables to illustrate */
@padding1: 10px;
@padding2: 20px;
@padding: 5px;
.compile_for_if when (@compile_for = "endpoint1"){
@img: @img_endpoint1;
@padding: @padding1;
}
.compile_for_if when (@compile_for = "endpoint2"){
@img: @img_endpoint2;
@padding: @padding2;
}
&{
.compile_for_if();
.img{
background-image:url("@{img}");
}
div{
padding: @padding;
}
}