9

The inline CSS styling for an option value in a html drop-down list does not work on Chrome and Safari, but does seem to work in Firefox and IE.

Snippet of the HTML code:

<option style="color:#4f5652;background:#f0f0ef;hite-space:nowrap;-webkit-appearance:button;text-overflow:ellipsis; padding:5px 4px 3px 4px;border-bottom:1px solid green" value="project">Project</option>
ArendE
  • 957
  • 1
  • 8
  • 14
  • 1
    provide some more code and elaborate the problem What exactly do you mean by "Does not work" ? – Ankit Sep 06 '12 at 14:02
  • take look for the url below on firefox and on chrome and see the difference: http://64.202.124.112/~cedro/en/ENERGY-EFFICIENCY/Internal-Lighting/Bassil-Fleihan-Institute (look on the drop down menu in the right : projects navigation) –  Sep 06 '12 at 14:03
  • white-space instead of hite-space, but not work –  Sep 06 '12 at 14:04

6 Answers6

18

color style works fine in <option> elements on Windows 7 with current versions of Chrome, Safari, Firefox, IE, and Opera, as well as on Mac with Firefox; but appears to be a no-op on Mac with Chrome and Safari. Seems like a bug to me.

ArendE
  • 957
  • 1
  • 8
  • 14
user2183078
  • 562
  • 6
  • 11
7

The short answer - you can not do that in Webkit based browsers. I.e. about padding take a look here

To overcome your problem you can change your <select> to a list <ul> and style its' <li> items. That will work in every browser guaranteed.

Community
  • 1
  • 1
Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
  • Well... it is an idea... but how to make
  • s to show and hide on
      clicks... simulating indeed the
  • – ElPiter Nov 24 '12 at 11:50
  • @ElPiter you can use some minimal JS/jQuery for that – Zoltan Toth Nov 24 '12 at 11:57
  • @ZoltanToth, good piece of advice. That is what I finally did and I think it had a nice looking :) – ElPiter Nov 26 '12 at 10:33
  • This is a great method, but you do lose the ability to select by typing and tabing between fields. – kwelch Jul 24 '15 at 17:15
  • So basically it looks like NOT using ` – Mick Belker - Pseudonym Feb 25 '19 at 07:50