有什么办法重置:after /:CSS规则之前的元素? [英] Is there any way to reset :after/:before CSS rules for an element?
问题描述
有任何方法(强健地)重置任何可能的:
和:之前
CSS规则创建元素?
Is there any way to (robustly) reset any possible :after
and :before
CSS rules for a newly created element?
通常你可以直接设置要重置的元素的样式规则(!important
如果你想确定),但是我不知道在:
Usually you can just set the style rules you want to reset on the element directly (with !important
if you want to be sure), but I don't know of any way of changing rules defined in :after
on the element only.
strong>示例。 jsFiddle 。
An example at jsFiddle.
:之前
/ :之后添加的内容规则会影响
clientHeight
。
The content added with the :before
/:after
rules is affecting the value returned by clientHeight
.
推荐答案
有一个 DOM2 API 。正确的做法是
document.getOverrideStyle(p, ':after').display = 'none'; // or
document.getOverrideStyle(p, ':after').cssText = 'display: none !important;';
不幸的是,没有浏览器实现它。 ( Webkit返回null , Firefox没有这种方法)。看起来CSS3甚至不再讨论这个了,也许因为用例很少。
Unfortunately, no browser has implemented it. (Webkit returns null, Firefox has no such method). It looks like CSS3 doesn't even bother talking about that anymore, maybe because the usecases are very rare.
所以你要做一些id / className魔术如上述或其他线程
So you're gonna have to do some id/className magic as suggested above or in the other thread
这篇关于有什么办法重置:after /:CSS规则之前的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!