2017-03-09 112 views
1

我有这个CSS3如何将元素后面的css3放在父元素之后?

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

但问题是蓝方应完全背后的红色长方形,所以只有蓝色正方形的右半部分伸出,但它出现在尽管我设置了Z指数。

有谁知道如何解决它?

由于

回答

5

默认伪元素都被视为它们的相关元件的后代。
只要删除z-index:10,它就像一个魅力。

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