less.css change theme variable in case of id

拟墨画扇 提交于 2020-01-15 05:09:42

问题


In my less file I define a variable theme colour as: @primaryColour: red;

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;
}

回答1:


You cannot overwrite variables in LESS (within the same scope). The documentation specifically says:

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);
}


来源:https://stackoverflow.com/questions/18462295/less-css-change-theme-variable-in-case-of-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!