可以通过 lesscss 中的另一个变量设置参数默认值吗?
使用 lesscss 时是否可以通过另一个变量声明默认参数?我已经尝试过但无法让它工作。实际上可能吗?
这里的目的是将@button_bg_color
设置为默认值,而不声明@button_gradient_from和@button_gradient_to
。
@button_bg_color: #9cc961;
@button_txt_color: #fff;
@darkened_button_bg_color: @button_bg_color - #2b2b2b;
.branded_button(@from_color: @button_bg_color, @to_color: @darkened_button_bg_color) {
color: @button_txt_color;
background-color: @from_color;
/* FireFox 3.6 */
background-image: -moz-linear-gradient(top, @from_color, @to_color);
/* Safari4+, Chrome */
background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, @from_color),color-stop(1, @to_color));
}
.button {
a {
.branded_button(@button_gradient_from, @button_gradient_to);
}
}
++++++++++++++++++++++++++++++++++++++++++++++
编辑:更改为混合类似的帖子:are variable mixin name in LESS possible? 但这失败了具有以下渲染:
.branded_button(@from_color: @button_bg_color {
color:#ffffff;
background-color:;
background-image:-moz-linear-gradient(top,,);
background-image:-webkit-gradient(linear,left bottom,left top,color-stop(0,),color-stop(1,));
}
When using lesscss is it possible to declare a default parameter via another variable? I've tried it but can't get it to work. Is it actually possible?
The intent here is to set @button_bg_color
as the default should @button_gradient_from and @button_gradient_to
not be declared.
@button_bg_color: #9cc961;
@button_txt_color: #fff;
@darkened_button_bg_color: @button_bg_color - #2b2b2b;
.branded_button(@from_color: @button_bg_color, @to_color: @darkened_button_bg_color) {
color: @button_txt_color;
background-color: @from_color;
/* FireFox 3.6 */
background-image: -moz-linear-gradient(top, @from_color, @to_color);
/* Safari4+, Chrome */
background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0, @from_color),color-stop(1, @to_color));
}
.button {
a {
.branded_button(@button_gradient_from, @button_gradient_to);
}
}
++++++++++++++++++++++++++++++++++++++++++
Edit: changed to a mixing per this similar post: are variable mixin names in LESS possible? but this fails with the following rendering:
.branded_button(@from_color: @button_bg_color {
color:#ffffff;
background-color:;
background-image:-moz-linear-gradient(top,,);
background-image:-webkit-gradient(linear,left bottom,left top,color-stop(0,),color-stop(1,));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在局部范围内重新定义全局变量。 Mixin 将使用新值进行调用。在局部范围之外,全局变量将保留其值。请参阅此 LESS 代码。
它将被编译到此 CSS 代码中。
请参阅演示。
You can redefine a global variable in the local scope. Mixin will be invoked with a new value. Outside the local scope the global variable will preserve its value. See this LESS code.
It will be compiled into this CSS code.
Please, see the demo.