Remove space when LESS variable value to string

一曲冷凌霜 提交于 2019-12-24 14:43:30

问题


Below is example less mixin code

.mixin(@option) {
  .set(@options) when (@options = a){
    @type: linear;
  }

  .set(@option);

  background: -webkit-~'@{type}'-gradient(...);
}

The output

background: -webkit- linear -gradient(...);

How can i remove the space around linear?


回答1:


Less does not support an inplace concatenation via variable interpolation in value statements. You need a temporary variable for this (+ an auxiliary variable in this particular case to handle parens), e.g.:

@end-func: ~')';

div {
    @func: ~'-webkit-@{type}-gradient(';
    background: @func ... @end-func;
}



回答2:


Try the following:

[less function]

.transition(@propValue) {

    -moz-transition: e(%("-moz-%a", @propValue));

    -webkit-transition: e(%("-webkit-%a", @propValue));

    -ms-transition: e(%("-ms-%a", @propValue));

    transition: @propValue;

}

[css]

.transition(e("transform 0.5s ease"));

[The output]

-moz-transition: -moz-transform 0.5s ease;

-webkit-transition: -webkit-transform 0.5s ease;

-ms-transition: -ms-transform 0.5s ease;

transition: transform 0.5s ease;


来源:https://stackoverflow.com/questions/31779829/remove-space-when-less-variable-value-to-string

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