简体   繁体   English

如何将css3放置在元素后面的父级后面?

[英]How to position css3 after element to be behind parent?

I have this css3 我有这个css3

  #chevrons > .chevrons-item { display:inline-block; text-decoration:none; color:black; padding:5px; font-size:18px; position:relative; margin-right:20px; border:1px solid gray; background-color:red; position:relative; z-index:10; } #chevrons > .chevrons-item:after { content:''; width: 21px; height: 21px; transform: rotate(45deg); border:1px solid gray; position:absolute; background-color:blue; top:4px; right:-12px; z-index:-1; } 
  <div id="chevrons"> <a href="/" class="chevrons-item">sdfsdf</a> <a href="/" class="chevrons-item">Bsdfsdf</a> <a href="/" class="chevrons-item">Csdfsdf</a> </div> 

But the problem is the blue square should be completely behind the red rectangle, so only the right half of the blue square sticks out, but it appears on top even though I set the z-index. 但是问题是蓝色正方形应该完全在红色矩形后面,因此只有蓝色正方形的右半部分会伸出,但是即使我设置了z-index,它也会出现在顶部。

Does anyone know how to fix it? 有谁知道如何修理它?

Thanks 谢谢

By default Pseudo-elements are treated as descendants of their associated element. 默认情况下,伪元素被视为其关联元素的后代。
Just remove the z-index:10 and it will work like a charm. 只需删除z-index:10 ,它会像魅力一样工作。

 #chevrons > .chevrons-item { display:inline-block; text-decoration:none; color:black; padding:5px; font-size:18px; position:relative; margin-right:20px; border:1px solid gray; background-color:red; position:relative; } #chevrons > .chevrons-item:after { content:''; width: 21px; height: 21px; transform: rotate(45deg); border:1px solid gray; position:absolute; background-color:blue; top:4px; right:-12px; z-index:-1; } 
 <div id="chevrons"> <a href="/" class="chevrons-item">sdfsdf</a> <a href="/" class="chevrons-item">Bsdfsdf</a> <a href="/" class="chevrons-item">Csdfsdf</a> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM