I have an HTML5 <select>
with several <option>
children, where each <option>
has its own back and foreground colors. This is done via CSS and is easy enough.
What I would like to do is to maintain the <option>
color in the <select>
after the <option>
has been selected. For example, let's say I have this (I'm not using CSS in the simple example below but in my real environment I am):
<select>
<option style="color:red">ABC</option>
<option style="color:blue" selected>DEF</option>
<option style="color:green">GHI</option>
</select>
I would like to use CSS to somehow "transfer" the back and foreground colors of the chosen <option>
to the <select>
so that the <select>
color is always in synch with the color of the chosen <option>
. If the user selects the third option in my example, it should appear green when selected. Choosing the first option and the text appears red. When the <select>
is initially displayed, it should have the back and foreground colors of the initial <option>
(blue foreground, in the example above).
I can do this through jQuery but I'd prefer to use CSS but I feel it probably can't be done.