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>
这篇关于如何更改选择中悬停选项的背景颜色和文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更改选择中悬停选项的背景颜色和文本?


基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01