嵌套变量参考 [英] Nested variable reference

查看:97
本文介绍了嵌套变量参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

@gutter-xs-width:  20;

@class:   'xs';

我想要类似的东西:

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

我该怎么办?

推荐答案

这在Less中很有可能,下面是它的完成方式:(在Less v2.5.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}";
}

要将变量的值与静态字符串连接在一起,Less中通常使用的格式为"string1-@{string2}". @{string2}评估@string2变量中包含的值,并将其附加到string1.

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.

这篇关于嵌套变量参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆