less.css在id的情况下更改主题变量 [英] less.css change theme variable in case of id
本文介绍了less.css在id的情况下更改主题变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的less文件中,我将可变主题颜色定义为:@primaryColour: red;
In my less file I define a variable theme colour as: @primaryColour: red;
但是当我的身体ID改变时,我想将整体主题颜色更改为'@primaryColour: blue;
But when the id of my body changes, I want to change the overall theme colour to '@primaryColour: blue;
如何重新定义该主题色?这不起作用:
How do I re-define this theme colour? This doesn't work:
@primaryColour: red;
body#secondTheme {
@primaryColour: yellow;
}
推荐答案
您不能覆盖LESS(在同一范围内)中的变量.该文档特别指出:
You cannot overwrite variables in LESS (within the same scope). The documentation specifically says:
请注意,LESS中的变量实际上是常量",因为它们只能定义一次.
Note that variables in LESS are actually ‘constants’ in that they can only be defined once.
我建议您使用类似以下的内容:
I suggesr you tu use something like this:
.colorDefs(@color) {
@primaryColour: @color;
}
body#firstTheme {
.colorDefs(red);
}
body#secondTheme {
.colorDefs(yellow);
}
这篇关于less.css在id的情况下更改主题变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文