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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:16:40  来源:igfitidea点击:

CSS - Change button background color on hover

htmlcss

提问by user3272321

I need change button background color on hover.

我需要在悬停时更改按钮背景颜色。

My CSS on jsfiddle: CSS

我在 jsfiddle 上的CSSCSS

My HTML :

我的 HTML :

<input type='button' class='btn btn-default btn-success btn-lg' value='test'/>

DEMO

演示

回答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 importantkeyword to overcome with other styles like below.

如果您将此类保持在其他样式之上,则需要使用important关键字来克服如下所示的其他样式。

.btn:hover
{
background-image:none !important;
background-color:#ff00ff !important;
}

DEMO

演示

回答by Kheema Pandey

you might use this solution as !importantmake the CSS invalid. In this case all the type= buttonwhich have .btnclass 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

祝你好运