I'm trying to set the background color of a select option like this:
<select>
<option class="yellow">Option 1</option>
<option class="blue">Option 2</option>
<option class="red">Option 3</option>
</select>
where the classes would be like this: background-color: red;
. The idea is that when the dropdown list is is shown, each option would have the appropriate background color.
It seems like it should be a simple thing to do, but after spending an hour here, I've come across a lot of answers that claim to solve this but they don't actually work. The options all have the default background color.
Here are some examples that don't work for me with Chrome 83.0.4103.116 and Safari 13.1 on Mac:
- https://stackoverflow.com/a/43740774
- https://stackoverflow.com/a/18092074 (Changing the select color works but not the option color)
- https://stackoverflow.com/a/12836286
They do work with FF on Mac.
Is this possible with latest Chrome and Safari on Mac? Javascript solutions ok.