【发布时间】:2017-08-11 22:39:14
【问题描述】:
我尝试做某事,但它根本不起作用。
这看起来很简单,我希望将:before 添加到具有背景的元素中,但每次我这样做时,::before 都会出现在容器前面。
.container{
position:relative;
z-index:1;
background:blue;
border:1 px solid white;
}
.container::before{
position:absolute;
content:"";
z-index:-1;
top:-10px;
left:-10px;
width:calc(100% + 20px);
height:calc(100% + 20px);
background:red;
}
【问题讨论】:
-
你希望 ::before 去哪里?在容器的左侧、右侧还是后面?
-
在容器后面..我简化了代码,但前面有一个我想放在它后面的渐变,这就是为什么他在位置顶部 -10px ,离开容器的 -10px (还有 calc )
标签: css css-selectors pseudo-element