我发现我可以用一点 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/