css select dropdown bold on some

后端 未结 5 1082
迷失自我
迷失自我 2021-02-13 05:30

On a select dropdown, I need to make certain items \'strong/bold\'.

How can I do this?

Example of what I ideally require:

相关标签:
5条回答
  • 2021-02-13 05:59

    This also works (Firefox 50 and Chrome 55). Items 3 and 5 are shown in bold

       <style>
        .bld {font-weight:bold;}
       </style>
       <select>
        <option value = "1">Kanakangi
        <option value = "2">Ratnangi
        <option class = "bld" value = "8">Hanumatthodi
        <option value = "9">Dhenuka
        <option class = "bld" value = "15">Mayamalavagowla
        <option value = "16">Chakravaaham
      </select>
    
    0 讨论(0)
  • 2021-02-13 06:01

    you could use :nth-child(N)

    option:nth-child(1), option:nth-child(4) {
        font-weight:bold;
    }
    

    Demo: http://jsfiddle.net/Sotiris/sqshN/

    Find more info and browser support for this pseudo-class at http://reference.sitepoint.com/css/pseudoclass-nthchild

    0 讨论(0)
  • 2021-02-13 06:05

    Using css in the works as a quicker, easier alternative

    <option value="value" style="font-weight: bold;">SELECT ME</option>
    
    0 讨论(0)
  • 2021-02-13 06:14

    You actually can't.

    The closest thing (you can't choose a bold item)

     <optgroup label="Swedish Cars">
        <option value="volvo">Volvo</option>
        <option value="saab">Saab</option>
      </optgroup>
      <optgroup label="German Cars">
        <option value="mercedes">Mercedes</option>
        <option value="audi">Audi</option>
      </optgroup>
    

    Which gives you this: enter image description here

    http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_optgroup

    You can also build one of your own but it won't be input an input tag (you should use inputs of your own).

    0 讨论(0)
  • 2021-02-13 06:19

    You could do it with jQuery.

      $('#Your select').append($("<option></option>").attr.css("font-weight" , "bold").html("Bold Text"));
    

    You'd have to add some logic to determine which options to bold, obviously.

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