I'm trying to change color of selection in select option. I was trying to do this:
option::selection {background: #ccc;}
option::-moz-selection {background: #ccc;}
option::-webkit-selection {background: #ccc; color:#fff;}
But it doesn't work. This works only for simple text, not to option. Is there any way to change color of selection? I dont need to change background of selected option. I need to change color of selection.
The colour of selected text can be easily changed by using the CSS | ::selection Selector. In the below code, we have used CSS ::selection on <h1> and <p> element and set its colour as yellow with green background.
You can change the background color and color of selected text by styling ::selection . Styling this pseudo element is great for matching user-selected text to your sites color scheme.
Attach Inspector, press Ctrl+Shift+LMB on that arrow and you'll see what you should change.
try this one maybe it will be helpful for you.
select{
margin:40px;
background: yellow;
color:#000;
text-shadow:0 1px 0 rgba(0,0,0,0.4);
}
option:not(:checked) {
background-color: #FFF;
}
HTML
<select>
<option val="">Select Option</option>
<option val="1">Option 1</option>
<option val="2">Option 2</option>
<option val="3">Option 3</option>
<option val="4">Option 4</option>
</select>
Demo JsFiddle: https://jsfiddle.net/hamzanisar/yfg8vdme/
Hope this is what you expected.
function ChangedSelection()
{
var x = document.getElementById("mySelect").selectedIndex;
var color =document.getElementsByTagName("option")[x].value;
var y = document.getElementById("mySelect");
y.style.color=color;
}
<select id="mySelect" onchange="ChangedSelection()" style="Color:red;">
<option value="red" selected="selected">Red</option>
<option value="blue">Blue</option>
<option value="Green">Green</option>
<option value="Yellow">Yellow</option>
</select>
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