如何更改单选按钮悬停颜色

发布于 2025-01-05 23:51:06 字数 292 浏览 1 评论 0原文

我使用这个 css 代码作为文本区域的悬停颜色并输入它在除 IE 之外的所有浏览器中正常工作,其显示如下图所示。如何将单选按钮背景仅设置为透明。

在此处输入图像描述

我的 css 代码:

 input:focus, input:hover, textarea:focus, textarea:hover {
 border: 0 none;
 background: blue;
 }

i am using this css code for hover color for the text area and inputs it works fine in all browsers except IE its show like the image below. How to set the radio button background only to transparent.

enter image description here

my css code:

 input:focus, input:hover, textarea:focus, textarea:hover {
 border: 0 none;
 background: blue;
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞陪衬 2025-01-12 23:51:06

由于您直接设置 input 样式,因此单选按钮和复选框也将成为目标。避免这种情况的一个简单方法是使用 :not() 选择器,如下所示: input:not([type=radio]):not([type=checkbox]):not( [type=submit]):not([type=image]):not([type=button]):focus。请注意,这在 IE<8(?) 中不起作用。

Since you're styling input directly, radiobuttons and checkboxes will also be targeted. An easy way to avoid that is to use the :not() selector like so: input:not([type=radio]):not([type=checkbox]):not([type=submit]):not([type=image]):not([type=button]):focus. Note that this doesn't work in IE<8(?) though.

橘香 2025-01-12 23:51:06

powerbuoy 的说法是正确的,除了正常的文本框之外,输入选择器还选择复选框和收音机。
但我有一个建议,您可以使用它来代替他的,它可以在更多浏览器中使用。
基本上,您可以向所有复选框和单选按钮输入添加一个类。
所以你的复选框和单选按钮 html 就变成了

<input type="checkbox" class="checkbox">
<input type="radio" class="radio">

,然后添加 css 来重置复选框和单选按钮的样式

input.checkbox, input.radio
{
    background:transparent;
}

powerbuoy is right about that the input selector select checkboxes and radios in addition to the normal text boxes.
but i have a suggestion that you can use instead of his that will work in more browsers.
basically you can add a class to all your checkbox and radio buttons inputs.
so your checkbox and radio html becomes

<input type="checkbox" class="checkbox">
<input type="radio" class="radio">

and then add the css to reset the style for the checkboxes and radios like that

input.checkbox, input.radio
{
    background:transparent;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文