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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:01:48  来源:igfitidea点击:

How to change the Color of the hovered Select-Option in FireFox

htmlcssdrop-down-menuhover

提问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.

我发现我可以将图像设置为背景。

jsfiddle demo

jsfiddle 演示

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

SELECTelements 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

It cannot be done with CSS alone. I recommend a jQuery+ Chosenplugin replacement for the <select>

仅靠 CSS 无法做到这一点。我推荐一个jQuery+ Chosen插件替代<select>

回答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