Animating a CSS gradient background on the hover event

前端 未结 3 1949
南旧
南旧 2021-01-07 06:08

I have some menu items that are styled using a background gradient on hover using the following styling:

#sidebar ul          


        
3条回答
  •  走了就别回头了
    2021-01-07 06:17

    Animation on gradients aren't supported yet. However this site provides a pleasing approach for a animated kind of feel on hover-

    http://sapphion.com/2011/10/css3-gradient-transition-with-background-position/

    Sample css:-

    #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;  
    } 
    

提交回复
热议问题