如何使用在最终样式表中未输出的less.js创建mixin [英] How do I create a mixin using less.js that doesn't output in the final stylesheet
问题描述
我正在我的less.js样式表中创建一些mixin,我不希望原始的mixin出现在最终输出中.
I'm creating some mixins in my less.js stylesheets where I don't want the original mixin to appear in the final output.
例如,我有几个规则,如下所示:
For example, I have a couple of rules like this:
.grid1 { width: 960px; }
然后将其应用到我想采用这些值的一个或多个元素上,
I'm then applying it to the element or elements I want to take those values like so:
.foo {
.grid1;
}
但是我的最终css文件同时存在.
But then my final css file has both in.
Less提供了哪些功能来创建原始混合,而又不将其渲染为css规则?
What facility does Less provide for creating the original mixin without rendering it as a css rule as well?
推荐答案
我能想到的最好的答案似乎是将mixin声明为参数mixin或作为bundle的一部分,带有或不带有任何参数.
The best answer I can come up with seems to be to declare the mixin as a parametric mixin or as part of a bundle, with or without no parameters.
例如
.grid1() { width: 960px; } /* Not rendered in final css */
相对于
.grid1 { width: 960px; } /* Will render */
(请注意没有括号)
有点骇人听闻,但我不确定为什么能做到这一点,为什么该语言应该为此目的有一些特殊之处.
Feels a bit of a hack, but I'm not sure why the language should have something special for that purpose if this does the trick.
这篇关于如何使用在最终样式表中未输出的less.js创建mixin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!