html - 样式 HTML 选择和选项标签

标签 html css html-select

我发现我可以用一点 CSS3 来风格化选项元素。我试图控制在鼠标悬停事件期间处于事件状态的元素的背景。我已经有效地使用了 :hover 选择器来控制这个功能。但是,当我的鼠标离开选项组时,字体仍然是白色的。有什么办法可以控制它吗?

option
{
    background-image: -webkit-gradient(     linear,     left bottom,     left top,     color-stop(0, rgb(237,233,233)),     color-stop(1, rgb(255,255,255)) );
    background-image: -moz-linear-gradient(     center bottom,     rgb(237,233,233) 0%,     rgb(255,255,255) 100% );
    color:#333333;
}
option:hover
{
    background-image: -webkit-gradient(     linear,     left bottom,     left top,     color-stop(0, rgb(20,26,85)),     color-stop(1, rgb(137,145,192)) );
    background-image: -moz-linear-gradient(     center bottom,     rgb(20,26,85) 0%,     rgb(137,145,192) 100% );
    color:#FFFFFF;
}

我不知道有什么方法可以控制事件元素的字体颜色。这也不一定是所选元素。

最佳答案

如果您正在为 anchor 标记执行此操作,请在此 Mainer 中定义类:

.option a{
background-image: -webkit-gradient(     linear,     left bottom,     left top,     color-stop(0, rgb(237,233,233)),     color-stop(1, rgb(255,255,255)) );
background-image: -moz-linear-gradient(     center bottom,     rgb(237,233,233) 0%,     rgb(255,255,255) 100% );
color:#333333;
}

.option a:hover{
background-image: -webkit-gradient(     linear,     left bottom,     left top,     color-stop(0, rgb(20,26,85)),     color-stop(1, rgb(137,145,192)) );
background-image: -moz-linear-gradient(     center bottom,     rgb(20,26,85) 0%,     rgb(137,145,192) 100% );
color:#FFFFFF;
}

它将正常工作。此外,当您在标签上时,您会看到鼠标悬停后悬停的东西形成该链接,这在您使用黑色时变得正常。

如果您正在使用任何其他标签,请在同一 Mainer 中使用

关于html - 样式 HTML 选择和选项标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7372748/

相关文章:

javascript - JQuery 注册表单点击弹出窗口

jquery - 为什么 div :hover work with jquery . 没有动画?

post - 如何启用/禁用选择标签并使用 knockout 将其发布(即使禁用)

jquery - 使选择框中选定的选项始终显示在顶部

html - 创建一个带滚动条的div

html - 柔性网格问题嵌套多个柔性方向组合

jquery - 如何在动态调用的元素上绑定(bind)关闭事件操作

reactjs - 如何将选择的 defaultValue 限制为 TypeScript 中选项的值之一

javascript - 对 flask render_template 进行 AJAX 调用的问题

html - 无法在 flex div 容器内的两行中显示 h3 标签