更改 <选择>高亮颜色 [英] Changing <select> highlight color
问题描述
如何使用 CSS 更改 的突出显示颜色,即光标经过时突出显示
的颜色?>
How do I change the highlighting color of <select>
that is the color that highlights <li>
while cursor passes over it by using CSS?
推荐答案
不知道你说的突出显示 的颜色"是什么意思,但听起来你想改变
元素的背景颜色.我试过了,没用,你总是得到系统颜色.
No idea what you mean about "the color that highlights <li>
", but it sounds like you want to change the background colour of <option>
elements. I tried it and it doesn't work, you always get the system color.
如果您想在鼠标悬停时突出显示整个 <select>
元素,这有点工作:
If you wanted to highlight the entire <select>
element on mouseover, this kinda works:
select:hover { background-color: red; }
但是在不同的浏览器中行为是不同的.例如,Chrome 不会突出显示下拉列表中的选项;Firefox 可以,但是如果您将鼠标移开并且它们仍然被拉下,它不会将它们更改回来.
However the behaviour is different in different browsers. For example, Chrome doesn't highlight the options in the drop down; Firefox does, but then it doesn't change them back if you move the mouse away and they are still pulled down.
正如在许多类似问题中所述,您无法可靠地设置表单控件的样式.参见此处了解更多详情.
As has been stated on many, many similar questions, you can't reliably style form controls. See here for more details.
这篇关于更改 <选择>高亮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!