2016-04-22 34 views
0

這裏我::後是小提琴證明我的問題:JSFiddle防止擋住了我的選擇

我正在做一個自定義的下拉列表(在現實中我使用的是icomoon圖標而不是V).. 。它看起來不錯,但對於::after父元素是阻斷選擇:(

<div class="select-style"> 
    <select> 
    <option value="">...</option> 
    <option value="1365">Some term</option>"; 
    </select> 
</div> 

CSS

.select-style { 
    width: 240px; 
    height: 26px; 
    border: 0; 
    padding: 0; 
    margin: 0; 
    position: relative; 
    &::after { 
    /*content: "\f107"; 
     font-family: "icomoon";*/ 
    content: "V"; 
    font-size: 18px; 
    position: absolute; 
    right: 7px; 
    top: 0; 
    } 
} 

select { 
    width: 100%; 
    height: 24px; 
    border: 1px solid rgb(199, 199, 199); 
    border-radius: 3px; 
    background-color: transparent; 
    -webkit-appearance: none; 
    -moz-appearance: none; 
    text-indent: 1px; 
    text-overflow: ""; 
    &::-ms-expand { 
    display: none; 
    } 
} 

我看着成JS打開下拉,卻發現Ø這不起作用。我甚至嘗試過使用z-index來查看是否有幫助...但由於某種原因,即使選擇具有透明背景,圖標也會隱藏起來。

我該如何使自定義圖標在選擇區域可見,但不會阻止我的選擇被點擊?

回答

2

添加position:relativez-index:1的選擇本身

https://jsfiddle.net/hbpqvkqL/

select { 
    ... 
    position: relative; 
    z-index: 1; 
} 
+0

不錯,工作。謝謝。 – smerny

+0

@smerny不客氣。很高興我能幫上忙。 –

1

yopu可以設置::後具有的z-index:-1;

.select-style { 
width: 240px; 
height: 26px; 
border: 0; 
padding: 0; 
margin: 0; 
position: relative; 
&::after { 
/*content: "\f107"; 
    font-family: "icomoon";*/ 
content: "V"; 
font-size: 18px; 
position: absolute; 
right: 7px; 
top: 0; 
z-index: -1; 
} 
} 
+0

這是我嘗試過的,它在我的頁面上不起作用......但是當我把它放在小提琴裏面時,它在那裏工作...不知道爲什麼這裏有差別。 – smerny

+0

@smerny確保你將位置設置爲相對,z-index僅適用於相對,絕對和固定 – Bojan

+0

@smerny它可能是一個背景。在這個小提琴中看到:https://jsfiddle.net/jmarikle/58vk33zs/2/。箭頭呈現在背景下方,導致它被「畫」在 –