2016-05-12 174 views
0

我有一個元素有兩個僞元素,:before:after。父母的位置與z-index: 0相關,兩個僞元素的絕對位置爲z-index: -1頂部僞元素的堆棧頂部

但是,我無法獲得頂層的父元素。我怎樣才能解決這個問題?

下面是說明這一問題的codepen:http://codepen.io/zthall/pen/NNmKgZ

的SCSS代碼:

.pokeball { 
    height: $size/5; 
    width: $size/5; 
    background: white; 
    border-radius: 50%; 
    border: ($size/20) solid $black; 
    position: relative; 
    margin: ($size * 4/5); 
    z-index: 1; 

    &:after, 
    &:before { 
    content: ''; 
    display: block; 
    width: $size; 
    height: $size/2; 
    border-radius: $size $size 0 0; 
    border: ($size/20) solid $black; 
    z-index: -1; 
    position: absolute; 
    } 

    &:after { 
    background: $red; 
    top: -$size/2; 
    left: -$size/2; 
    } 

    &:before { 
    background: $white; 
    top: 0; 
    left: -$size/2; 
    transform: rotate(180deg); 
    } 
} 

的HTML:

<div class="pokeball"></div> 
+0

'的z-index:0'讓家長建立堆疊環境,然後這是不可能的。只要刪除它。可能的[CSS:在父元素後面](http://stackoverflow.com/q/34190157/1529630)或[HTML:獲取要顯示的子元素(較低的z-index)比其父元素?](http ://stackoverflow.com/q/2503705/1529630) – Oriol

+0

謝謝,@Oriol。有趣的是,現在它只是在動畫中消失。 – Zack

回答