9

我试图在编译之前覆盖一些引导 LESS 变量,例如

// Core variables
@import "variables.less";

// Trying to override @white from variables.less
@white: #de1de1;

// other bootstrap @imports....

上面的代码没有覆盖@white,但是如果我@white在 variables.less 文件的末尾添加,它可以正常工作。

看起来变量只能在同一个文件中被覆盖。但这对我来说没有意义,因为我认为 LESS 不是那样工作的。例如其他@import文件(从上面的代码中省略)使用该@white变量。如果他们能够在 variables.less 文件之外使用它,为什么我不能在文件之外覆盖它?

我正在使用Less Php 0.3.9 来编译我的代码。

注意:我刚刚尝试了以下代码:

// Core variables
@import "variables.less";
@import "variables-custom.less";

现在的值@white取自 variables-custom.less (这在一定程度上解决了我的问题)。它仍然没有解释为什么我的原始代码不起作用。将不胜感激答案。

4

1 回答 1

3

变量将按照您将导入设置为编译的顺序被覆盖(并且可用)。

例如:

@import "variables.less";   //@white is set
@import "styles.less";        //UPDATED @white NOT available
@import "variables-custom.less";   //Update @white
@import "styles2.less";        //UPDATED @white available

因此,只要确保如果您不打算使用 variables.less 而是使用 variables-custom.less,则将其放在所有其他 .less 文件之前(当然,variables.less 除外)。

于 2013-03-14T22:44:36.700 回答