[英]remove/ignore css declaration or rule WITHOUT javascript
I'm guessing the answer is "no", but I'll ask anyway.我猜答案是“否”,但我还是会问。 Is there a CSS property/value that allows you to remove or ignore a previous CSS declaration or rule?
是否有 CSS 属性/值允许您删除或忽略以前的 CSS 声明或规则? Example:
例子:
<div class="foo">whatever</div>
div {background: red;}
.foo {background: blue;}
.foo:hover {background: <something-that-will-let-it-default-back-to-red>;}
Values of inherit
, initial
, unset
, or revert
do not work for this. inherit
、 initial
、 unset
或revert
的值对此不起作用。 The idea is to avoid the need to explicitly set it back to the style it would have had if the rule had not existed.这个想法是为了避免需要明确地将其设置回规则不存在时应有的样式。 Using a CSS variable would also be explicit.
使用 CSS 变量也是明确的。 With Javascript, one could just toggle the "foo" class on hover. I'm just wondering if there's a way to do something similar with CSS only, even if it's only being considered as part of a CSS draft proposal.
对于 Javascript,可以在 hover 上切换“foo”class。我只是想知道是否有一种方法可以仅对 CSS 执行类似的操作,即使它仅被视为 CSS 提案草案的一部分。
Doesn't exactly "remove" a previous CSS declaration/rule, but it does have the.net effect that I was looking for.不完全“删除”以前的 CSS 声明/规则,但它确实具有我正在寻找的.net 效果。
div {background: red;}.foo:not(:hover) {background: blue;}
<div class="foo">whatever</div>
What about:关于什么:
div {background: red;}
.foo {background: blue;}
.foo:hover {background: red !important;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.