Changing the background color of the selected opti

2019-01-20 02:38发布

enter image description here

I have to create a select box like this. I have been able to get this tree structure using optgroup but I am facing problems in changing the default background color of the selected option from default color to this orange color. I am aware of js solutions but I am more interested in pure HTML/CSS solution. It would be better if it will work in every browser, but no pressure ;)

Thanks in advance.

2条回答
SAY GOODBYE
2楼-- · 2019-01-20 02:52

It is not possible to do this with HTML/CSS. The colors of the select elements are Operating System specific and so cannot be changed with CSS or HTML. Javascript solutions have been developed and they're (so far) the only way to do it :)

查看更多
放荡不羁爱自由
3楼-- · 2019-01-20 03:17

In Firefox you can use the css background-image property together with the :checked CSS pseudo-class selector to achieve it.

option:checked, option:hover {
    color: white;
    background: #488f8f repeat url("mycolor.gif");
}

You can find a css demo with a different color on my website www.speich.net

查看更多
登录 后发表回答