重用较少的变量作为参数混合的参数传递(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.
更多推荐
发布评论