dotLess - 与以标签名称开头的选择器混合
我正在使用 dotLess 'mixin',如下所示:
.base-button-style
{
...
}
.specific-button-style
{
.base-button-style; //mixin
...
}
效果很好。但现在我需要更改基本样式的选择器,通过添加标签名称来赋予它更高的优先级:
input.base-button-style
{
...
}
但是,dotLess 似乎不喜欢这样,因此 .less 文件根本无法“解析”。我尝试将其更改为这样,但没有更好的结果:(
input.base-button-style
{
...
}
.specific-button-style
{
input.base-button-style;
...
}
也就是说,在基本样式和用作 mixin 的位置都有标签名称。)
有办法让这个工作吗?
请注意,我在 HTML 中同时使用了基本按钮样式和特定按钮样式。
I'm using a dotLess 'mixin' like this:
.base-button-style
{
...
}
.specific-button-style
{
.base-button-style; //mixin
...
}
This works fine. But now I need to change the selector of the base style to give it a higher precedence by adding the tag name:
input.base-button-style
{
...
}
However, dotLess doesn't seem to like this, so the .less file can't be "parsed" at all. I've tried changing it to this with no better result:
input.base-button-style
{
...
}
.specific-button-style
{
input.base-button-style;
...
}
(That is, having the tag name in both the base style and where it is used as a mixin.)
Is there a way to make this work?
Note that I use both base-button-style and specific-button-style in my HTML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定 mixin 是否可以有选择器,因为它们是从最终代码中删除的有效函数。
最好将
.special-button-style
嵌套在.base-button-style
下,如下所示:.edit 的 &: 运算符
和.orange
类有效地生成.button.edit
和.button.orange
类。因此,HTML 元素具有class='button edit'
。这适用于 IE7+ 以及所有其他常见浏览器。I'm not sure if the mixins can have selectors, as they are effectively functions that are stripped out of the final code.
It might be better to nest your
.specific-button-style
under the.base-button-style
like this:The &: operator for the
.edit
and.orange
classes effectively produces.button.edit
and.button.orange
classes. The HTML element thus hasclass='button edit'
. That will work on IE7+, and all the usual others.