【发布时间】:2019-02-21 15:37:59
【问题描述】:
我正在寻找避免全局扩散变量的最佳方法。
我用这个配置做了一个测试:
_import.less
@test: #FFF;
_import2.less
@test: #000;
test.less
@import (reference) "_import";
body {
background: @test;
}
test2.less
@import (reference) "_import2";
div {
background: @test;
}
index.less
@import "test";
@import "test2";
lessc index.less test.css 的输出看起来仍然像
body {
background: #000;
}
div {
background: #000;
}
但我正在寻找的是:
body {
background: #FFF;
}
div {
background: #000;
}
使用 less 2.7 或 3.9 会产生相同的行为。
有人知道解决方案吗?
谢谢
【问题讨论】:
-
这是设计使然:两次定义变量时,使用最后一次定义的变量,从当前范围向上搜索。 ref 如果要避免它,使用不同的变量,或动态导入文件(基于条件)