更改选择框中所选选项的背景颜色 [英] Changing the background color of the selected options in a select box
问题描述
我必须创建一个这样的选择框.我已经能够使用 optgroup 获得这种树结构,但是我在将所选选项的默认背景颜色从默认颜色更改为这种橙色时遇到了问题.我知道 js 解决方案,但我对纯 HTML/CSS 解决方案更感兴趣.如果它可以在所有浏览器中运行会更好,但没有压力;)
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 ;)
提前致谢.
推荐答案
HTML/CSS 无法做到这一点.选择元素的颜色是操作系统特定的,因此不能用 CSS 或 HTML 更改.Javascript 解决方案已经开发出来,它们是(到目前为止)唯一的方法:)
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 :)
这篇关于更改选择框中所选选项的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!