所以我有这个html标记
<div class="text-white">
<div class="textClass"></div>
</div>
textClass
类有一个较少定义的变量,它将标题颜色变为黑色,但是我想要的是,如果textClass
元素具有text-white
父对象,则textClass
标题颜色随后将变为白色。这可能吗?
这是我到目前为止所拥有的,但是没有用:
//I defined the color of the heading
@heading-color: black;
//My attempt to redefine the heading-color base on class
.text-white > .textClass {
@heading-color: white;
}
如果这不可能,那么我怎样才能少用一点呢?
谢谢您的帮助。
在这种情况下,您可以在其中不带-
字符的情况下命名变量,例如:
@headingColor: black;
.text-white > .textClass {
@headingColor: white;
background-color: @headingColor;
}
.some-heading {
background-color: @headingColor;
}
输出:
.text-white > .textClass {
background-color: #ffffff;
}
.some-heading {
background-color: #000000;
}
注意:覆盖它时,可以在合并范围内使用它。