views:

13279

answers:

5

Is it possible to change the border color on a <select> element in an HTML form?

The border-color style works in Firefox but not IE.

I could find no real answers on Google.

+2  A: 

No, the <select> control is a system-level control, not a client-level control in IE. A few versions back it didn't even play nicely-with z-index, putting itself on top of virtually everything.

To do anything fancy you'll have to emulate the functionality using CSS and your own elements.

Diodeus
It being a system-level control or not doesn't make up for the fact that you can't style it (properly) though. I.e it doesnt pose onovercomeable challenges for the IE team even if it was.
Martijn Laarman
Yeah, they were lazy-asses.
Diodeus
OwnerDrawing is ever so much fun though ;)
Martijn Laarman
Thanks for confirmation of the system-level control thing.
+3  A: 

As Diodeus stated, IE doesn't allow anything but the default border for <select> elements. However, I know of two hacks to achieve a similar effect :

  1. Use a DIV that is placed absolutely at the same position as the dropdown and set it's borders. It will appear that the dropdown has a border.

  2. Use a Javascript solution, for instance, the one provided here.

It may however prove to be too much effort, so you should evaluate if you really require the border.

Cerebrus
A: 

In IE it just isn't going to happen. A reasonable alternative is to create a control that functions like a tag using jQuery. Here's one that does just that and is compatible with FF/IE6/IE7.

DavGarcia
+3  A: 

I would consinder enclosing that select block within a div block and setting the border property like so:

<div style="border: 2px solid blue;">
  <select style="width: 100%;">
    <option value="Sal">Sal</option>
    <option value="Awesome">Awesome!</option>
  </select>
</div>


You should be able to play with that to accomplish what you need.

fuentesjr
Works need enough to what I need, thanks!
Umm... wasn't that what I suggested too? Okay, maybe I didn't <b>show</b> how to do it. ;-)
Cerebrus
Cerebrus: As I posted this answer I noticed you had posted the suggestion as well, so for that I voted up your answer. :)
fuentesjr
+1  A: 
<del>You can set the border color in IE however there are some issues.</del>

Argh... I could have sworn you could do this... just tested and realized I wasn't correct. The notes below still apply though.

1.) in IE8 (Beta1 -> RC1) changing the border color or the background color/image causes a de-theming of the control in WindowsXP (the drop arrow and box look like Windows 95)

2.) you still can't style the options within the select control very well because IE doesn't support it. (see bug #291)

scunliffe