通用“供应商”混合
定义供应商的 mixin 是 LESS 下的常见任务,即:
.box-shadow() {
-moz-box-shadow:@arguments;
-webkit-box-shadow:@arguments;
-o-box-shadow:@arguments;
-ms-box-shadow:@arguments;
box-shadow:@arguments;
}
.border-radius() {
-moz-border-radius:@arguments;
-webkit-border-radius:@arguments;
-o-border-radius:@arguments;
-ms-border-radius:@arguments;
border-radius:@arguments;
}
...
但似乎有点重复...
我想要的是一个通用的 vendor
mixin 为我做这件事,即:
.vendors(@prop, @val) {
-moz-@prop:@val;
-webkit-@prop:@val;
-o-@prop:@val;
-ms-@prop:@val;
@prop:@val;
}
然后定义 box-shadow
mixin 会像这样简单:
.box-shadow() {
.vendors(box-shadow, @arguments);
}
问题是我的 .vendors
mixin 无法编译...
我尝试过:
.vendors(@prop, @val) {
-moz-@prop: @val; /* Error */
~"-moz-@{prop}": @val; /* Error */
~`"-moz-@{prop}": @val; /* Error */
}
您知道如何做到这一点吗?
干杯
Defining vendors' mixins is common task under LESS, ie:
.box-shadow() {
-moz-box-shadow:@arguments;
-webkit-box-shadow:@arguments;
-o-box-shadow:@arguments;
-ms-box-shadow:@arguments;
box-shadow:@arguments;
}
.border-radius() {
-moz-border-radius:@arguments;
-webkit-border-radius:@arguments;
-o-border-radius:@arguments;
-ms-border-radius:@arguments;
border-radius:@arguments;
}
...
But it seems a bit repeating...
What I would like is a generic vendor
mixin which do this for me, ie:
.vendors(@prop, @val) {
-moz-@prop:@val;
-webkit-@prop:@val;
-o-@prop:@val;
-ms-@prop:@val;
@prop:@val;
}
Then defining box-shadow
mixin would as simple as:
.box-shadow() {
.vendors(box-shadow, @arguments);
}
The problem is my .vendors
mixin does not compile...
I tried:
.vendors(@prop, @val) {
-moz-@prop: @val; /* Error */
~"-moz-@{prop}": @val; /* Error */
~`"-moz-@{prop}": @val; /* Error */
}
Do you have an idea on how to do this?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Stylus 有这个,叫做 插值,例如:
— 然后,
产生:
\o/
Stylus has this, which is called Interpolation, eg:
— Then,
yields to:
\o/
我认为更干净的另一种选择是创建供应商列表,然后迭代该列表以创建您想要的特定样式。下面是一个示例:
这将创建您想要支持的供应商列表,然后允许您重用它们。如果稍后您决定要支持另一个前缀或要删除一个前缀,您只需将其从列表中删除即可。
然后您将使用如上所示的列表:
Another option, that I think is a little cleaner, would be do create a list of vendors and then iterate over that list to create the particular styles you want. Here's an example:
This creates a list of vendors that you want to support and then allows you to reuse them. if later, you decide you want to support another prefix or want to remove one, all you have to do is remove it from the list.
And then you would use the list just as shown above:
我很确定现在拥有它的人更少了。我在 Meteor.js 项目中使用了这段代码:
I'm pretty sure less now has it. I've used this code in a Meteor.js project: