concatenate values in less (css) without a space

非 Y 不嫁゛ 提交于 2019-11-27 20:04:21

One solution, although a little ugly, would be to used escaped strings:

@degs: ~"@{rotation}deg"
@degs-ie: @rotation / 90;
transform: rotate(@degs);
filter: ~"DXImageBlahBlah(rotation=@{degs-ie})"

Note you need less.js v1.1.x for this.

A cleaner approach is to use unit (official documentation):

unit(@rotation, deg)

which in your example becomes:

transform: rotate(unit(@transition, deg));

Documentation:

unit(dimension, unit)

  • dimension: A number, with or without a dimension
  • unit (optional): the unit to change to, or if omitted it will remove the unit

Thank you cloudhead. Since the escaping for LESS PHP is a little different, this is what worked for me:

.rotation(@rotation:90){
  @degs: e("@{rotation}deg");
  @degs-ie: @rotation / 90;

  -webkit-transform: rotate(@degs);
  -moz-transform: rotate(@degs);
  transform: rotate(@degs);
  filter: e("progid:DXImageTransform.Microsoft.BasicImage(rotation=@{degs-ie})");
}

For anyone that found this old item about concatenation without spaces, there is a bug/feature request in LESS #1375 (Opened in 2013, unfixed as of Jan 2016) that describes the problem.

Problem:

@CharTinySpace: \\2009;
content: "@CharTinySpace@CharTinySpace";

Output:

content: " \2009 \2009 ";

Which adds extra space to the display.

A solution can be to use an embedded JavaScript replacement:

@CharTinySpace: \\2009;
content: `"@{CharTinySpace}@{CharTinySpace}".replace(/ /g,"")`;

Output:

content: "\2009\2009";

Not the best solution, but the only one that worked in my instance where I want readable varables instead of unicode escape values.


Update: Thanks to seven-phases-max, the proper solution is MUCH simpler.
@CharTinySpace: \\2009;
content: "@{CharTinySpace}@{CharTinySpace}";

I'm leaving this here in case the JavaScript option is a useful clue to future discoverers.

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