css - :after : z-index doesn't work

标签 css z-index pseudo-element

我想将黑色矩形 (:after) 放在 h2 后面,但 z-index 不起作用。

我在 html 中有这段代码

  <h2>Ce que tu auras peut-être un jour ou l'autre...</h2>

CSS 中的这个:

#general .page h2 {
position: relative;
text-indent: -9999px;
width: 718px;
margin-bottom: 50px;
height: 116px;
z-index: 10;
background: url(img/banniere-hi-04.png);
}

#general .page h2:after {
display: block;
content: "";
position: absolute;
top: -15px;
left: 658px;
width: 544px;
height: 72px;
z-index: -1;
background: black;
}

问题是这样的(这里有一个黑色矩形): http://www.robinmastromarino.be/dataviz04/

感谢您的帮助!

最佳答案

您需要给出<div class="page">相对位置和正 z 索引,然后删除 <h2> 上的 z 索引当伪元素创建一个新的堆叠上下文时

More info as to why


示例:

关于css - :after : z-index doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15395930/

相关文章:

html - 在 IE7 中扩展出现在画廊下方的菜单

javascript - 使用 javascript(或 jQuery)选择和操作 CSS 伪元素,例如::before 和::after

css - CSS `content` 属性如何用于 WebKit 中的 `img` 元素?

JavaScript 循环变量作用域

java - 在 JavaFX ScatterChart 中为数据系列设置八种以上颜色

css - 避免在:asbolute位置叠加div

css - 包含 z-index 是否会增加浏览器处理时间?

javascript - 如何根据 div 外部的数字更改 div 的尺寸?查询/CSS

html - 两个 div 的 z-index 覆盖了 childs 的 z-index

css - 固定元素上的径向框阴影