-5

Given the following HTML code:

<select>
  <option>yellow</option>
  <option>red</option>
  <option>blue</option>
</select>

For example, changing the color of second character in text "blue".

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
user787415
  • 11
  • 3
  • 2
    @BoltClock: Did you really add the sentence "Given that following html code:"? Or is the revision history lying? – thirtydot May 12 '12 at 03:48
  • @thirtydot says the same thing for me ...haha! – BumbleShrimp May 12 '12 at 03:51
  • At max you can style the nth option using `nth-child(x)`, I don't think you can style a specific letter in the option. Unless you are willing to try a custom drop down.. but they are not going to be real ` – Selvakumar Arumugam May 12 '12 at 03:54
  • 2
    Duplicate of http://stackoverflow.com/questions/3354979/styling-part-of-the-option-text as Jonathon pointed out. – Selvakumar Arumugam May 12 '12 at 03:58
  • 2
    @thirtydot: No, apparently the OP had ninja edited it out for whatever reason just as I was fixing the Markdown. The system needs to learn about revision merging. – BoltClock May 12 '12 at 04:01

3 Answers3

2

I do not believe there is currently a way to do that in CSS or (X)HTML. As "DaneSoul" pointed out, you could style the <option>s themselves, but you can't individually style different parts of the text inside of them.

The <option> tag cannot have any children other than a text node.

This question/answer has more information, confirming this.

Community
  • 1
  • 1
BumbleShrimp
  • 2,150
  • 23
  • 42
0
<select>
  <option id='option1'>yellow</option>
  <option id='option2'>red</option>
  <option id='option3'>blue</option>
</select>

Then add styles in CSS

#option3{ color: blue; }

If you need do it in dynamic, you can use JQuery:

$("#option3").css("color", "blue");
DaneSoul
  • 4,491
  • 3
  • 21
  • 37
0

The only way this could be done is to create your own drop down list with DIVs, SPANs, perhaps a UL or two, and a bit of JavaScript (something like a CSS dropdown navigation menu cxould work too I suppose) then use JavaScript to set the value to be sent for your form.

Probably more work than it's worth.

DACrosby
  • 11,116
  • 3
  • 39
  • 51