【发布时间】:2012-06-20 17:41:45
【问题描述】:
当静态定位时,::before 伪元素堆叠(z-index)在子元素的内容之前,但在子元素的背景之后。任何人都可以解释为什么甚至是如何发生这种情况,或者这是所有主要浏览器都存在的问题吗?
<style>
div { background-color:yellow; width:400px; }
div::before { background-color:red; content:"div::before"; }
div::after { background-color:green; content:"div::after"; }
div p { background-color:blue; color:white; margin:-15px 0; padding:0; }
</style>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sed tellus sed tellus sodales hendrerit tristique et elit.</p>
</div>
【问题讨论】:
-
如果将两个伪元素都显示为块,
::before背景会隐藏在p背景后面:jsfiddle.net/BoltClock/cVzs8/1 注意它们默认显示为内联。 -
@BoltClock:这很奇怪,但是,从表面上看,这很有趣……这是一个错误,还是设计使然? (如果你有能力或有能力回答这个问题。)
-
这不起作用,但它不应该有一个冒号吗?
:before和:after? -
@Kobi:CSS3 中为伪元素引入了双冒号符号:w3.org/TR/selectors/#pseudo-elements
-
@David Thomas:你不认为我是 CSSWG 的成员,是吗? :O (我是多么希望...)
标签: css z-index pseudo-element