How to change background color and text of hover options in select?(如何更改选择中悬停选项的背景颜色和文本?)
问题描述
我想在悬停时将此蓝色更改为透明,并将文本颜色更改为红色
I want to change this blue to transparent and the text color to red on hover
推荐答案
这是一个工作示例.- 单个选择选项无法设置样式.
Here is a working example. - A single select option cannot be styled.
我们在这里所做的是使用在点击时触发的 size
将选择更改为多选.转换为多选后,您可以设置选项悬停样式.
What we are doing here is changing the select to multiple selects using size
which is triggered onclick. Once converted to a multiple select you can then style the option hover.
.blue:hover {background: blue;}
.green:hover {background: green;}
.red:hover {background: red;}
<select onfocus='this.size=3;' onblur='this.size=0;'
onchange='this.size=1; this.blur();'>
<option class="blue" >blue background</option>
<option class="green" >green background</option>
<option class="red" >red background</option>
</select>
这篇关于如何更改选择中悬停选项的背景颜色和文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更改选择中悬停选项的背景颜色和文本?


- 如何显示带有换行符的文本标签? 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01