Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing change in colour and background colour of selected option when blurred

Tags:

html

css

This is my select box in focus:

enter image description here

And my select box while blurred:

enter image description here

As you can see, the selected option for my focused select box is highlighted blue, whereas for my blurred select box, the selected option is highlighted grey.


This is my HTML if anyone needs it:

<select size='9' id="functions_select">
    <option>Option 1</option>
    <option>Option 2</option>
    <option selected>Option 3</option>
</select>

CSS:

* {
    outline: none;  
}

Is it possible to make it such that when blurred, the selected option for my select box will remain blue?

like image 435
chris97ong Avatar asked Dec 03 '25 13:12

chris97ong


1 Answers

I have a solution for you:

* {
    outline: none;  
}


option:checked {
    color: white;
    -webkit-text-fill-color: white;
    background: #1e90ff repeat url("https://i.sstatic.net/Istm3.jpg");
}
<select size='9' id="functions_select" multiple>
    <option>Option 1</option>
    <option>Option 2</option>
    <option selected>Option 3</option>
</select>

It using background-image for option, this won't let browser use default background color.

like image 170
Pedram Avatar answered Dec 05 '25 05:12

Pedram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!