In my PHP code, I am pulling a table of two columns from the database and displaying both of them in a dropdown list. Following is the code snippet:
echo "<select id='isv' class='required'>";
while($row = pg_fetch_row($result)){
echo "<option><span class='options'>" . $row[0] . "</span> " . $row[1] . "</option>";
}
echo "</select><br>";
I wanted to separate them both by styling them differently. So I wrote the following CSS:
.options
{
color: red;
float: left;
text-align: right;
width: 15em;
margin-right: 1em;
}
However, the style is not getting applied to the options. What exactly do I need to change in this code?
<option>elements can not be styled that way, you’ll have to design your own implementation using JavaScript. Drop-down menus (<select>s) are mostly styled by the browser chrome, not by CSS. In addition, the<option>element may not have any child elements.Here is a good reference for what you can style via CSS: http://bavotasan.com/2011/style-select-box-using-only-css/