小编Tom*_*aus的帖子

带有伪元素的Z-index

我创建了一个带有before-pseudo元素的'header'元素.pseudeo元素必须位于父元素后面.一切都很好,直到我给'标题'一个z-index.

我想要的是:前景中的黄色"标题",背景中的红色伪元素以及黄色"标题"元素上的简单z-index为30.

header { 
    background: yellow;
    position:relative;
    height: 100px;
    width: 100px;
    z-index:30; /*This is the problem*/
}

header::before { 
    content:"Hide you behind!";
    background: red;
    position:absolute;
    height: 100px;
    width: 100px;
    top:25px;
    left:25px;
    z-index:-1;
}
Run Code Online (Sandbox Code Playgroud)

您可以在此链接(http://jsfiddle.net/tZKDy/)上测试我的问题,并在de'header'元素上设置/删除z-index时看到问题.

css z-index pseudo-element

20
推荐指数
1
解决办法
2万
查看次数

标签 统计

css ×1

pseudo-element ×1

z-index ×1