Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css select dropdown bold on some <option>'s

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

How can I do this?

Example of what I ideally require:

<option value="#"><strong>Andorra</strong></option> 
<option value="#">--Grandvalira</option> 
<option value="#">--Vallnord</option> 
<option value="#"><strong>Austria</strong></option> 
<option value="#">--Amadé</option> 
<option value="#">--Bad Kleinkirchheim</option> 
<option value="#">--Mallnitz</option>
like image 296
user991830 Avatar asked Jan 31 '12 11:01

user991830


People also ask

How do I bold text in a dropdown in HTML?

To bold the text in HTML, use either the strong tag or the b (bold) tag.

How do I select a dropdown in CSS?

There are many ways to design a <select> dropdown menu using CSS. The Dropdown Menu is mainly used to select an element from the list of elements. Each menu option can be defined by an <option> element that can nested inside the <select> element.


3 Answers

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

like image 70
Royi Namir Avatar answered Oct 13 '22 10:10

Royi Namir


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

like image 39
Sotiris Avatar answered Oct 13 '22 08:10

Sotiris


Using css in the works as a quicker, easier alternative

<option value="value" style="font-weight: bold;">SELECT ME</option>
like image 43
Ben Davis Avatar answered Oct 13 '22 09:10

Ben Davis