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

后端 未结 4 680
小蘑菇
小蘑菇 2021-01-18 07:38

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

<
相关标签:
4条回答
  • 2021-01-18 07:49

    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

    0 讨论(0)
  • 2021-01-18 07:51
    #htmldisabled:first-child{
        font-weight:bold;
    }
    
    0 讨论(0)
  • 2021-01-18 08:00

    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>
    
    0 讨论(0)
  • 2021-01-18 08:07

    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 :)

    0 讨论(0)
提交回复
热议问题