Html CSS - 悬停时更改按钮背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24819910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS - Change button background color on hover
提问by user3272321
回答by Suresh Ponnukalai
You can achieve it in the following way. This solution will work if you add this class at the bottom of your CSS.
您可以通过以下方式实现它。如果您在 CSS 底部添加此类,则此解决方案将起作用。
.btn:hover
{
background-image:none;
background-color:#ff00ff;
}
If you keep this class in top of the other styles, you need to use important
keyword to overcome with other styles like below.
如果您将此类保持在其他样式之上,则需要使用important
关键字来克服如下所示的其他样式。
.btn:hover
{
background-image:none !important;
background-color:#ff00ff !important;
}
回答by Kheema Pandey
you might use this solution as !important
make the CSS invalid. In this case all the type= button
which have .btn
class will only affected.
您可能会使用此解决方案!important
使 CSS 无效。在这种情况下,所有type= button
具有.btn
类的只会受到影响。
input[type="button"].btn:hover{background:red;}
回答by Senthilkumar Manoharan
you can achieve using the below
您可以使用以下方法实现
.btn:hover{
//apply styles here
}
回答by MeMTn
this is really easy, you just have to add the css selector :hover
这真的很简单,你只需要添加 css 选择器 :hover
for example:
例如:
.btn-success:hover{
color: #ffffff;
background-color: #51a351;
}
回答by Faran Khan
You can use :hover with the class for the mouse hover event. Like if you want you can use:
您可以将 :hover 与鼠标悬停事件的类一起使用。如果你愿意,你可以使用:
btn:hover {
color:blue;
}
best of luck
祝你好运