在 html 中悬停时更改选择列表选项背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17740391/
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
Change Select List Option background colour on hover in html
提问by srihari
Is it possible to change the default background color of the select list option on hover?
是否可以在悬停时更改选择列表选项的默认背景颜色?
HTML:
HTML:
<select id="select">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
select {
-webkit-border-radius:25px; -moz-border-radius:25px; border-radius:25px;
}
select:hover {
background-color:gren;
}
option:hover {
background-color:yellow;
}
option {
-webkit-border-radius:25px; -moz-border-radius:25px; border-radius:25px;
color:blue;
background-color:yellow;
}
I have tried option :hover{background-color:red;}
, but it is of no use. Does anybody know how to do this?
我试过 option :hover{background-color:red;}
,但没有用。有人知道怎么做这个吗?
采纳答案by Kiran Ruth R
Currently there is no way to apply a css to get your desired result . Why not use libraries like choosenor select2. These allow you to style the way you want.
目前没有办法应用 css 来获得你想要的结果。为什么不使用selected或select2 之类的库。这些使您可以按照自己的方式设计样式。
If you don want to use third party libraries then you can make a simple un-ordered list and play with some css.Here is thread you could follow
如果您不想使用第三方库,那么您可以制作一个简单的无序列表并使用一些 css。这是您可以遵循的线程
How to convert <select> dropdown into an unordered list using jquery?
回答by maximkou
No, it's not possible.
不,这不可能。
It's really, if not use native selects, if you create custom select widget from html elements, t.e. "li".
真的,如果不使用本机选择,如果您从 html 元素创建自定义选择小部件,te“li”。