Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select box style

Status
Not open for further replies.

rico14d

Programmer
Apr 8, 2002
135
GB
I am trying to change the color of an option in a select box. I have achieved as in the first example below but i really want to do this dynamically using CSS. Is it possible to do? I tried the bottom e.g. and it didnt work.

<option style=&quot;color:red;&quot; value=&quot;EP&quot;>EUROPCAR</option>

<option class=&quot;myclass&quot; value=&quot;EP&quot;>EUROPCAR</option>

thanks, rich
 
Hi rich,

classes should work ! This works for me:

<style>
.opt1 {
color:#C00000;
background-color:yellow
}
.opt2 {
color:#0000C0;
background-color:#FF8080
}

</style>

<option class=&quot;opt1&quot; value=&quot;yourvalue&quot;>Your text</option>
<option class=&quot;opt2&quot; value=&quot;yourvalue&quot;>Your text 2</option>

However, if you generate your page dynamically you can give HTML elements a unique ID and give that unique ID a unigue style.

<style>
#opt1 {
color:#C00000;
background-color:yellow
}
#opt2 {
color:#0000C0;
background-color:#FF8080
}

</style>

<option id=&quot;opt1&quot; value=&quot;yourvalue&quot;>Your text</option>
<option id=&quot;opt2&quot; value=&quot;yourvalue&quot;>Your text 2</option>

Hope this helps,
Erik

<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
It did work.
I was just linking to the wrong stylesheet.
Doh!
thanks for replying anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top