CSS 如何在悬停时更改按钮的颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3898781/
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 22:56:00  来源:igfitidea点击:

How can I change a button's color on hover?

cssbuttonhover

提问by getaway

I need to change the color of a button on hover.

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

Here is my solution, but it doesn't work.

这是我的解决方案,但它不起作用。

a.button {
   display: -moz-inline-stack;
   display: inline-block;
   width: 391px;
   height: 62px;
   background: url("img/btncolor.png") no-repeat;
   line-height: 62px;
   vertical-align: text-middle;
   text-align: center;
   color: #ebe6eb;
   font-family: Zenhei;
   font-size: 39px;
   font-weight: normal;
   font-style: normal;
   text-shadow: #222222 1px 1px 0;
}
a.button a:hover{
     background: #383;
}

回答by Matchu

a.button a:hovermeans "a link that's being hovered over that is a child of a link with the class button".

a.button a:hover表示“悬停在该链接上的链接是该类链接的子链接button”。

Go instead for a.button:hover.

改为a.button:hover.

回答by BrunoLM

Seems your selector is wrong, try using:

似乎您的选择器有误,请尝试使用:

a.button:hover{
     background: #383;
}

Your code

你的代码

a.button a:hover

Means it is going to search for an aelement inside awith class button.

意味着它将使用类按钮搜索a内部元素a

回答by Penh

a.button:hover{
    background: #383;  }

works for me but in my case

对我有用,但就我而言

#buttonClick:hover {
background-color:green;  }