作者:麦芽糖的-寂寞 | 来源:互联网 | 2023-01-04 20:35
请看以下示例:
.article, .note {
color: var(--text-color, red);
}
.theme {
--text-color: blue;
}
.theme .note {
--text-color: unset;
}
是否可以通过取消设置CSS变量使第二个"注"再次变为红色?
我知道我只能应用CSS变量,.article
但我假设我有很多类似的元素,我希望应用主题,但只有少数豁免.然后维护选择器会相当繁琐.
我可以将主题选择器更改为.theme :not(.note)
但不适用于.note
嵌套在其他元素中的任何元素.
1> dippas..:
您可以使用该值initial
,因为IE 不支持CSS变量,这不是使用initial
此问题(IE 也不支持)
.article,
.note {
color: var(--text-color, red);
}
.theme {
--text-color: blue;
}
.theme .note {
--text-color: initial;
}