Html 如何更改 FireFox 中悬停的 Select-Option 的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7027551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the Color of the hovered Select-Option in FireFox
提问by oliholz
I want to change the Color of the hovered Select-Option in FireFox which has default blue background and white foreground.
我想更改 FireFox 中悬停的 Select-Option 的颜色,它具有默认的蓝色背景和白色前景。
I tried:
我试过:
<select name="select" size="1">
<option>0</option>
<option class="test">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
.test:hover {
color:green;
background-color:yellow;
text-decoration:underline;
}
But it doesn't work. See Example.
A FireFox specific solution is sufficient.
但它不起作用。请参见示例。
一个 FireFox 特定的解决方案就足够了。
采纳答案by oliholz
I found out that I can set an Image as Backround.
我发现我可以将图像设置为背景。
But it is only painted on :hover, when I exit the mouse from the option it will by system rendered.
但它只绘制在 :hover 上,当我从系统呈现的选项中退出鼠标时。
回答by Diodeus - James MacFarlane
SELECT
elements are rendered by the OS, not HTML. You cannot style this element.
SELECT
元素由操作系统呈现,而不是 HTML。您无法设置此元素的样式。
You can use a HTML+CSS replacement using JavaScript to simulate SELECT though.
不过,您可以使用 JavaScript 使用 HTML+CSS 替换来模拟 SELECT。
回答by andyb
回答by Dani
I think you may need to work with CSS combinators like this:
我认为您可能需要使用这样的 CSS 组合器:
select>option.test:hover
{
color: #1B517E;
cursor: pointer;
}
Basically you are specifying this:
基本上你正在指定这个:
Parent > children . class : event
父 > 子。类别:事件
All children in select tags inside which options with the class ".test" will have the style specified in brackets.
select 标签中的所有子项,其中带有类“.test”的选项将具有括号中指定的样式。
IMPORTANT: It works on Firefox, but not in Chrome.
重要提示:它适用于 Firefox,但不适用于 Chrome。
Here's a reference can help you: http://www.w3schools.com/css/css_combinators.asp
这里有一个参考可以帮助你:http: //www.w3schools.com/css/css_combinators.asp