I'm trying to make a simple colour picker using html/css with just four colours - so far so good.
What's annoying me is that when you hover over an option in the dropdown, it changes to blue because of the hover state - but I can't seem to disable this in the css.
I've tried the select:hover
and option:hover
properties but nothing seems to work. Is there an alternative to this without using a library that will achieve the same effect?
function changeColor() {
var c = this.options[this.selectedIndex].value;
document.getElementById("result").style.backgroundColor = c;
}
document.getElementById("colourPicker").addEventListener("change", changeColor);
body {
font-family: Arial, sans-serif;
}
#colourPicker {
width: 50px;
}
#result {
padding: 20px 20px 20px 20px;
border: 1px solid black;
}
.white {
background-color: #ffffff;
}
.red {
background-color: #ff0000;
}
.amber {
background-color: #ffa500;
}
.green {
background-color: #00b300;
}
<div id="test">
Pick a colour:
<select id="colourPicker">
<option value="#ffffff" class="white"></option>
<option value="#ff0000" class="red"></option>
<option value="#ffa500" class="amber"></option>
<option value="#00b300" class="green"></option>
</select>
</div>
<br><br>
<div id="result">
<center>Result Colour</center>
</div>