Nested variable reference

一个人想着一个人 提交于 2019-12-11 12:57:40

问题


I have:

@gutter-xs-width:  20;

and

@class:   'xs';

I'd like to have something like:

padding-left:  @gutter-(@class)-width;

How can I do it?


回答1:


That is very much possible in Less and the below is how it is done: (tested in Less v2.5.1)

@gutter-xs-width:  20;
@class:   'xs';
a{
  padding-left:  ~"@{gutter-@{class}-width}";
}

For concatenating the value of a variable with a static string, the format that is generally used in Less is "string1-@{string2}". @{string2} evaluates the value contained within the @string2 variable and appends it to string1.

Here we have to do an extra @{} around the value that is obtained after concatenation because we don't want the concatenated string as the output but rather the value contained by the variable whose name is the same as the concatenated string.



来源:https://stackoverflow.com/questions/32386303/nested-variable-reference

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