另一个关于使用 CSS 的问题。
我想让标题的背景颜色在悬停时从当前颜色过渡到另一种颜色(由于多个站点具有不同的颜色)。
我做了一个CSS-transition-animation为此,但它似乎没有用。 我做错了什么?
#header
{
background-color: #3cff9c;
float: left;
text-align: center;
width: 100%;
}
#header:hover
{
/*Animation*/
-webkit-animation: colorChange_blue 1s; /* Safari, Chrome, Opera*/
-moz-animation: colorChange_blue 1s; /*Firefox*/
animation: colorChange_blue 1s; /*Standard*/
/*Safari, Chrome, Opera*/
@-webkit-keyframes colorChange_blue
{
from
{background-color;}
to
{background-color: #008c74;}
}
/*Firefox*/
@-moz-keyframes colorChange_blue
{
from
{background-color: currentColor;}
to
{background-color: #008c74;}
}
/*Standard*/
@keyframes colorChange_blue
{
from
{background-color: currentColor;}
to
{background-color: #008c74;}
}
}
最佳答案
如何在没有关键帧的情况下解决它,而只使用带有过渡的标准悬停?
#header {
height: 50px;
width: 100px;
background-color: #3cff9c;
transition: background-color 1s;
}
#header:hover {
background-color: #008c74;
}
<div id="header"></div>
关于html - CSS 颜色过渡不适用于 :hover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28691833/