Consider the following HTML markup:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>search/master</title>
<style type="text/css">
select{
background-color: pink;
}
option{
background-color: white;
}
</style>
</head>
<body>
<p>
<select>
<option>one........</option>
<option>two........</option>
</select>
</p>
</body>
</html>
Output on FF as follows: (Similar output comes on Chrome, Safari and Opera as well)
But output on IE as follows:
What is the reliable and simple workaround to make the output on IE looks similar to other browsers?
The problem occurs when we specify some background color for the options inside the select element and the select element itself.
Workaround : Apply style (background-color) to the option elements only when the select element is in focussed state. ( it is only during focussed state of the select element we actually see the option elements inside it )
If you definitely want to do this, you could use a 1px x 1px background image, and set the option to
:transparent
See the jsfiddle example i have done for you
If you make both background color( for select and option) pink, it looks exactly the same in every browser. A better solution maybe..do not specify the background color on the option element at all....
First remove the following css value, it's giving the OPTIONS a white background color and thus hiding the select's pink background color in IE.
Second always enclose Form elements inside the Form and Fieldset tag like shown below:-
Third Form and Fieldset have a default border and padding values so in css you can add this code to remove those default values:
So in short the main reason for IE not displaying the Select Box correctly is because the select element isn't enclosed in FORM and the OPTION's White background color value.
Hope this helps.