重用较少的变量作为参数混合的参数传递(Reuse less variable passed as an argument for parametric mixins)

编程入门 行业动态 更新时间:2024-10-27 14:22:45
重用较少的变量作为参数混合的参数传递(Reuse less variable passed as an argument for parametric mixins)

是否可以使用较小的变量作为参数混合的参数?

这是一个例子:

@red: #ff0000; @blue: #0000ff; .body-theme(@color){ background: @color; p { color: @color; } } body{ &.red{ .body-theme(@red); } &.blue{ .body-theme(@blue); } }

这个例子并不是很聪明,但它应该说明我想重用css的一部分,只选择将颜色设置为参数。

谢谢你的帮助!

Is it possible to use a less variable as an argument for parametric mixins?

Here's an example:

@red: #ff0000; @blue: #0000ff; .body-theme(@color){ background: @color; p { color: @color; } } body{ &.red{ .body-theme(@red); } &.blue{ .body-theme(@blue); } }

This example isn't really clever but it should illustrate that I want to reuse a part of the css with the option to only set the color as the parameter.

Thanks for your help!

最满意答案

如果有疑问,请测试一下: http : //lesstester.com/在这里尝试你的例子表明它会起作用,给出这个输出:

body.red { background: #ff0000; } body.red p { color: #ff0000; } body.blue { background: #0000ff; } body.blue p { color: #0000ff; }

如果您不确定某些事情是否可以在更少或更少的情况下完成,您应该在将来使用它来快速测试。

When in doubt, test it out: http://lesstester.com/ trying your example out here shows that it will work, giving this output:

body.red { background: #ff0000; } body.red p { color: #ff0000; } body.blue { background: #0000ff; } body.blue p { color: #0000ff; }

You should use this in the future to quickly test, if you are unsure if something can be done in less or not.

更多推荐

本文发布于:2023-08-07 10:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463313.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   较少   变量   Reuse   variable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!