2015-06-11 136 views
12

這是我反倒:自定義選擇與字體真棒

HTML

<label class="select"> 
    <select name="email" id="email"> 
    <option>aaaa</option> 
    <option>aaaa</option> 
    <option>aaaa</option> 
    <option>aaaa</option> 
    <option>aaaa</option> 
    <option>aaaa</option> 
    </select> 
</label> 

CSS

.cforms select { 
    -webkit-appearance: none; 
    -moz-appearance: none; 
    appearance: none; 
} 


.select { 
    position:relative; 
    display: -moz-inline-stack; 
    display: inline-block; 
    vertical-align: middle; 
    zoom: 1; 
    *display: inline; 
    margin-top:40px; 
} 

.select:after { 
    content: "\f0dc"; 
    font-family: FontAwesome; 
    color: #000; 
    padding:8px; 
    position:relative; 
    right:35px; 
    top:0px; 
    background:red; 
    z-index:-1; 
    width:10%; 
    line-height:10%; 
} 

問題

其實,沒有箭頭出現接近我的選擇。

請幫我解決這個問題。

我在網上搜索了一些例子,但是我不能使它成功。

謝謝。

+2

'input's如'select'元素不能有僞元素AFAIK –

回答

19

也許這樣

.select { 
 
    border: 1px solid #ccc; 
 
    overflow: hidden; 
 
    height: 40px;  
 
    width: 240px; 
 
    position: relative; 
 
    display: block; 
 
} 
 

 
select{  
 
    height: 40px; 
 
    padding: 5px; 
 
    border: 0; 
 
    font-size: 16px;  
 
    width: 240px; 
 
    -webkit-appearance: none; 
 
    -moz-appearance: none; 
 
    appearance: none; 
 
} 
 
.select:after { 
 
    content:"\f0dc"; 
 
    font-family: FontAwesome; 
 
    color: #000; 
 
    padding: 12px 8px; 
 
    position: absolute; right: 0; top: 0; 
 
    background: red; 
 
    z-index: 1; 
 
    text-align: center; 
 
    width: 10%; 
 
    height: 100%;  
 
    pointer-events: none; 
 
    box-sizing: border-box; 
 
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/> 
 
<label class="select"> 
 
    <select name="email" id="email"> 
 
     <option>aaaa1</option> 
 
     <option>aaaa2</option> 
 
     <option>aaaa3</option> 
 
     <option>aaaa4</option> 
 
     <option>aaaa5</option> 
 
     <option>aaaa6</option> 
 
    </select> 
 
</label>

+0

它的作品,謝謝! –

+1

對於我來說,在這個答案中真正重要的是'pointer-events:none;',因爲它可以防止點擊事件的中斷! –