Nested variable reference

2019-08-15 17:17发布

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?

标签: less
1条回答
贼婆χ
2楼-- · 2019-08-15 18:06

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.

查看更多
登录 后发表回答