I have a select
box and I\'m trying to change the background color of the options when the select
box has been clicked and shows all the options.
Another option is to use Javascript:
if (document.getElementById('selectID').value == '1') {
document.getElementById('optionID').style.color = '#000';
(Not as clean as the CSS attribute selector, but more powerful)
Similar to some of the answers, but not really stated, is to add a class to the actual option tag and use css classes...this is currently working for me without issue on IE (see above ss).
<select id="reviewAction">
<option class="greenColor">Accept and Advance Status</option>
<option class="redColor">Return for Modifications</option>
</select>
CSS:
.greenColor{
background-color: #33CC33;
}
.redColor{
background-color: #E60000;
}
Yes, you can set this by the opposite way:
select { /* desired background */ }
option:not(:checked) { background: #fff; }
Check it working bellow:
select {
margin: 50px;
width: 300px;
background: #ff0;
color: #000;
}
option:not(:checked) {
background-color: #fff;
}
<select>
<option val="">Select Option</option>
<option val="1">Option 1</option>
<option val="2">Option 2</option>
<option val="3">Option 3</option>
<option val="4">Option 4</option>
</select>
My selects would not color the background until I added !important to the style.
input, select, select option{background-color:#FFE !important}