Use CSS3 transitions with gradient backgrounds

后端 未结 16 1613
慢半拍i
慢半拍i 2020-11-21 22:18

I\'m trying to transition on hover with css over a thumbnail so that on hover, the background gradient fades in. The transition isn\'t working, but if I simply change it to

16条回答
  •  星月不相逢
    2020-11-21 22:58

    One work-around is to transition the background position to give the effect that the gradient is changing: http://sapphion.com/2011/10/css3-gradient-transition-with-background-position/

    CSS3 gradient transition with background-position

    Although you can’t directly animate gradients using the CSS transition property, it is possible to animate the background-position property to achieve a simple gradient animation:

    The code for this is dead simple:

    #DemoGradient{  
        background: -webkit-linear-gradient(#C7D3DC,#5B798E);  
        background: -moz-linear-gradient(#C7D3DC,#5B798E);  
        background: -o-linear-gradient(#C7D3DC,#5B798E);  
        background: linear-gradient(#C7D3DC,#5B798E);  
      
        -webkit-transition: background 1s ease-out;  
        -moz-transition: background 1s ease-out;  
        -o-transition: background 1s ease-out;  
        transition: background 1s ease-out;  
      
        background-size:1px 200px;  
        border-radius: 10px;  
        border: 1px solid #839DB0;  
        cursor:pointer;  
        width: 150px;  
        height: 100px;  
    }  
    #DemoGradient:Hover{  
        background-position:100px;  
    }  

提交回复
热议问题