I have a HTML dropdown select menu with first option is disabled. I would like to show that default disabled option in gray color, but once I selected another value, I would like this appear as blue. How can I achieve this ?
I managed to get the selected option appear as gray, and the selectable options to appear as blue in the list. But both disabled and not disables options will appear as gray anyway once they are selected :
select:not(:checked) {
color: gray;
}
select option:not(:disabled){
color: #000098;
}
The “:checked” selector of pseudo-class is used to change the selected option color. The :checked is utilized along with the “option” of the drop-down menu, and after that, you can set the color of the selected option.
Change Select List Option background colour on hover. Changing <select> highlight color. Change color of selection.
You can do that if you put required tag to select element.
HTML:
<select name="number" required>
<option value="" disabled selected hidden>Placeholder</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
CSS:
select:required:invalid {
color: gray;
}
select, option {
color: blue;
}
https://jsfiddle.net/p63eg7d8/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With