2017-03-09 160 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>

相關問題