11

The following CSS works in FF, but not in IE(at least 8.0), how can I make sure that the text align in the center for IE8.0? Thanks!!!

select, option {
    text-align: center;
}
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
WilliamLou
  • 1,914
  • 6
  • 27
  • 38

3 Answers3

12

Unfortunately, you can't change the alignment of SELECT items in IE, although it surprises me that even IE 8 keeps this bad habit.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
2

Given that this is not possible in IE, I think you would have to resort to:

  1. Implementing your own SELECT widgets. There are many JS libraries that do this, mostly because SELECT inputs are hard to style.

  2. Insert the appropriate whitespace in front of the smaller options.

Edit: looks like whitespace doesn't work, but HTML space does:

<SELECT>
   <OPTION>&nbsp;&nbsp;&nbsp;SMALL</OPTION>
   <OPTION>&nbsp;&nbsp;LARGER</OPTION>
</SELECT>

That's quite a hack...

Chase Seibert
  • 15,703
  • 8
  • 51
  • 58
  • 1
    Whitespace doesn't work, IE appends them to the right hand side of the item - for whatever reason... – Pekka Dec 15 '09 at 23:27
-1

You can make a class and call it using the 'STYLE TAG' in the option field.::

For Eg:--

<style type="text/css">
select { width: 400px; text-align:center; }
select .lt { text-align:left; }
</style>




<select name="state" class="ddList">
<option value="">(please select a state)</option>
<option class="lt" value="--">none</option>
<option class="lt" value="AL">Alabama</option>
<option class="lt" value="AK">Alaska</option>
<option class="lt" value="AZ">Arizona</option>
<option class="lt" value="AR">Arkansas</option>
<option class="lt" value="CA">California</option>
<option class="lt" value="CO">Colorado</option>
</select> 
Vishu Singhvi
  • 417
  • 2
  • 7
  • 24
  • This solution fails on IE just like the one the author of the question presented. Not even talking about the fact it is not faithful to what seems to be his desire: centering not only the text in the select but also in the options... – Daniel Jun 11 '15 at 07:31