CSS颜色过渡不起作用:悬停

时间:2015-02-24 09:12:46

标签: html5 css3 colors css-transitions

使用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;}
    }
}

1 个答案:

答案 0 :(得分:0)

如何在没有关键帧的情况下解决问题,只使用转换进行标准悬停?

#header {
    height: 50px;
    width: 100px;
    background-color: #3cff9c;
    transition: background-color 1s;
}

#header:hover {           
    background-color: #008c74;
}
<div id="header"></div>

相关问题