lesscss:字符串插值,mixin和条件

时间:2013-12-19 11:52:49

标签: css less

如何在具有条件的mixin中使用字符串插值?

我的文件较少:

@line-height-topbar : 1.43;
@line-height-base : 1.43;

.topbar {
color : #000;
.lineHeight(topbar);
}

我的mixin:

.lineHeight(@prefix,@line-height-base) when not (~"@{line-height-@{prefix}}" = @line-height-base) {
    line-height: ~"@{line-height-@{prefix}}";
}

css输出:

.topbar {
color : #000;
line-height : 1.43;
}

通常情况下,我预计这个css(因为@ line-height-topbar = @ line-height-base):

.topbar {
color : #000;
}

1 个答案:

答案 0 :(得分:2)

重新分配到另一个局部变量似乎有效,如下:

.lineHeight(@prefix; @check: ~"@{line-height-@{prefix}}") when not (@check = @line-height-base) {
    line-height: ~"@{line-height-@{prefix}}";
}

这可能与解决~"@{line-height-@{prefix}}"的方式/时间的处理顺序有关。

相关问题