Adding vendor prefixes with LESS mixin

爱⌒轻易说出口 提交于 2019-12-10 19:12:05

问题


I'm getting a Syntax Error for this mix-in:

.vendors(@statement){
  @statement;
  -moz-@statement;
  -webkit-@statement;
}

Any way to do this, or do mixin variables have to be on the right side of a :?


回答1:


Since Less v2 you can use the autoprefix plugin to prefix your properties, which seems to be a better alternative. The autoprefix plugin add browser prefixes leveraging the autoprefixer postprocessor. For client side compiling (in the browser) you can use -prefixfree.

As already mentioned by @ScottS here you can use variable interpolation in selectors since Less v1.6, which enables you to do:

.prefix(@property, @value)
{
    -webkit-@{property}:@value;
    @{property}:@value;
}
selector {
    .prefix(property,value);
}

outputs:

selector {
  -webkit-property: value;
  property: value;
}

You should also read: Am I overcomplicating my LESS for vendor prefixes?




回答2:


That's a lame answer, but I don't think it's possible.




回答3:


There's no way to do that, but there are workarounds. If it worked, I think it would be something like this:

.vendors(@prop, @val){
  ~"-webkit-@{prop}:@{val}";
}

Note: this doesn't work.

Here's a very long discussion on the topic: https://github.com/cloudhead/less.js/pull/698

You might be able to make use of this library: less-properties



来源:https://stackoverflow.com/questions/12537474/adding-vendor-prefixes-with-less-mixin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!