我试图用:后伪元素CSS选择器样式一个元素
#element {
position: relative;
z-index: 1;
}
#element::after {
position:relative;
z-index: 0;
content: " ";
position: absolute;
width: 100px;
height: 100px;
}
似乎::后面的元素不能比元素本身更低。
有没有办法让伪元素低于元素本身?
这里有两个问题:
The CSS 2.1 specification states that "The :beforeand :after pseudo-elements elements interact with other boxes, such as run-in boxes, as if they were real elements inserted just inside their associated element." Given the way z-indexes are implemented in most browsers, it's pretty difficult (read, I don't know of a way) to move content lower than the z-index of their parent element in the DOM that works in all browsers.
Number 1 above does not necessarily mean it's impossible, but the second impediment to it is actually worse: Ultimately it's a matter of browser support. Firefox didn't support positioning of generated content at all until FF3.6. Who knows about browsers like IE. So even if you can find a hack to make it work in one browser, it's very likely it will only work in that browser.
我能想到的唯一一件事是跨浏览器工作是使用javascript插入元素,而不是CSS。我知道这不是一个很好的解决方案,但是:before和:after伪选择器看起来并不能解决这个问题。