How to bold the first option of a select across all browsers?

荒凉一梦 提交于 2020-01-11 08:35:07

问题


I have tried to bold the first option of the select box but it's only working in Firefox, not other browsers (Chrome, IE). Here is the code I've tried.

HTML

<select id="htmldisabled">
    <option class="bold">test1</option>
    <option>test2</option>
    <option>test3</option>
    <option>test4</option>
    <option>test5</option>
    <option>test6</option>
</select>

CSS

.bold {
     font-weight:bold;   
}

See demo at jsfiddle.


回答1:


#htmldisabled:first-child{
    font-weight:bold;
}



回答2:


As you've discovered, it can't be done cross-browser ;)

Best to use a selectbox replacement script if you need special formatting or display




回答3:


To my knowledge it doesnt work in IE unless you style the select tag:

select{
    font-weight:bold;
}

However this will influence all options. I dont know of another css-only solution, but would be interested in one as-well :)




回答4:


Just try,

css

option:first-child {
     font-weight:bold;   
   }

HTMl

<select id="htmldisabled">
    <option>test1</option>
    <option>test2</option>
    <option>test3</option>
    <option>test4</option>
    <option>test5</option>
    <option>test6</option>
</select>


来源:https://stackoverflow.com/questions/8356797/how-to-bold-the-first-option-of-a-select-across-all-browsers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!