2015-12-15 81 views
4

需要大寫選擇框選項標記的第一個字母。如何使用css將選擇選項中的第一個字母大寫

這是什麼嘗試:

HTML:

<select> 
    <option class="selected">test1</option> 
    <option>test2</option> 
    <option>test3</option> 
</select> 

CSS:

select option.selected::first-letter{ 
    text-transform:capitalize; 
} 
+1

可能一些答案dublicate http://stackoverflow.com/questions/34188117/how-to-capitalize-only-the-first-letter-of-an-html-option-element-using-css –

+0

只要'select {text-transform:capitalize}'應該可以工作。 這裏是一個工作小提琴演示:http://jsfiddle.net/jf0ahqvo/embedded/result/ – sachin

+0

我不認爲這是重複的問題。因爲這裏的OP只要選擇期權首字母大寫。 – ketan

回答

-1

試試這個代碼。如果你想選擇大寫的選項,那麼你可以在HTML中做如下的代碼。這應該適用於大多數瀏覽器。

select option { 
    text-transform: capitalize; 
} 

<select> 
    <option class="selected">Test1</option> 
    <option>test2</option> 
    <option>test3</option> 
</select> 
+2

可能dublicate http://stackoverflow.com/questions/34188117/how-to-capitalize-only-the-first-letter-of-an-html-option-element-using-css –

+0

@Prajwal,它確定你複製從另一個用戶的代碼,但至少添加一些行來解釋太... Thanx –

+0

@Leothelion謝謝你的傢伙我做。 –

相關問題