Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何将伪元素放在父元素后面?_Css_Z Index_Pseudo Element - Fatal编程技术网

Css 如何将伪元素放在父元素后面?

Css 如何将伪元素放在父元素后面?,css,z-index,pseudo-element,Css,Z Index,Pseudo Element,我寻找解决方案并尝试了来自的所有建议,但都失败了。 我想做一个边界作为父元素后面的peseudo元素 .member\u profile-container{ 弹性基准:50雷姆; 位置:相对位置; z指数:4; } .会员资料{ 填充顶部:150%; 背景图像:url('../images/irene.jpg'); 背景重复:无重复; 背景位置:中心; 背景尺寸:封面; 盒影:0-1rem.5rem 1rem rgba(0,0,0,0.3); 保证金权利:4rem; 变换:旋转(-5度)tr

我寻找解决方案并尝试了来自的所有建议,但都失败了。
我想做一个边界作为父元素后面的peseudo元素

.member\u profile-container{
弹性基准:50雷姆;
位置:相对位置;
z指数:4;
}
.会员资料{
填充顶部:150%;
背景图像:url('../images/irene.jpg');
背景重复:无重复;
背景位置:中心;
背景尺寸:封面;
盒影:0-1rem.5rem 1rem rgba(0,0,0,0.3);
保证金权利:4rem;
变换:旋转(-5度)translateX(-10%);
动画:扩展1s轻松。向前扩展5s;
}
.成员简介:之前{
内容:'';
位置:绝对位置;
左:0;
排名:0;
身高:100%;
宽度:100%;
边框:10px纯白;
变换:旋转(-5度)translateX(-10%);
动画:扩展1s轻松。向前扩展5s;
}

您需要对伪元素应用负的
z-index

e、 g.
z-index:-6

工作示例:

div{
宽度:100px;
高度:180像素;
利润率:20px 60px;
背景色:rgb(255,0,0);
}
div::之后{
内容:'';
位置:绝对位置;
顶部:-6px;
左:2px;
z指数:-6;
宽度:100px;
高度:180像素;
利润率:20px 60px;
边框:6px实心rgb(0,0,0);
变换:旋转(-30度);
}

尝试向伪元素添加负z索引

例如


为了让它工作,我不得不修改一下你的html。
因为
中的转换。member\uu profile
在这个级别创建了一个堆叠上下文,因为
::在
元素之前,
z-index
只会在
member\uu profile
中移动伪元素

HTML

通过在容器上使用“
position:relative;z-index:1;
”,我在这个级别上创建了一个堆叠上下文,并可以使用
z-index对其子级进行自由重新排序
如果您使用
z-index
而没有在容器中创建堆叠上下文,那么您将在文档中已创建堆叠上下文的其他地方使用堆叠上下文,或者如果之前没有创建堆叠上下文,则最终使用正文。
如果您希望容器后面的边框而不是概要文件,只需移动即可
位置:相对;z索引:1;
“向上移动一个父对象(不是复制它,而是移动它)。


要了解有关堆叠上下文的更多信息:

太好了,原因是
transform
property!它创造了新的背景。谢谢!
.yourclass:: pseudoelement {
    z-index: -1;
}
 <div class="member__profile-container">
     <div class="member__profile"></div>

     <!-- moved the pseudo-element to a sibling element -->
     <!-- removing 'the transform' inside .member__profile and 
          keeping the pseudo element would also work -->

     <div class="member__undercover"></div>
 </div>
.member__profile-container {
  /* creating a stacking context on the parent */
  position: relative;
  z-index: 1;
  flex-basis: 50rem;
  /* added color to make position clearer */
  background-color: green;
}


.member__profile {
  position: relative;
  padding-top: 150%;
  background-image: url('../images/irene.jpg');
  /* added color to make position clearer */
  background-color: red;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  box-shadow: 0 -1rem .5rem 1rem rgba(0, 0, 0, 0.3);
  margin-right: 4rem;
  transform: rotate(-5deg) translateX(-10%);
  z-index: 0;
}

.member__undercover {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 100%;
  border: 10px solid white;
  transform: rotate(-5deg) translateX(-10%);
  /* added color to make position clearer */
  background-color: blue;
  z-index:-1;
}