Use CSS3 transitions with gradient backgrounds

后端 未结 16 1820
慢半拍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 23:09

    Try use :before and :after (ie9+)

    #wrapper{
        width:400px;
        height:400px;
        margin:0 auto;
        border: 1px #000 solid;
        position:relative;}
    #wrapper:after,
    #wrapper:before{
        position:absolute;
        top:0;
        left:0;
        width:100%;
        height:100%;
        content:'';
        background: #1e5799;
        background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%);
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8));
        background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);
        background: -o-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);
        background: -ms-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);
        background: linear-gradient(to bottom, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%);
        opacity:1;
        z-index:-1;
        -webkit-transition: all 2s ease-out;
        -moz-transition: all 2s ease-out;
        -ms-transition: all 2s ease-out;
        -o-transition: all 2s ease-out;
        transition: all 2s ease-out;
    }
    #wrapper:after{
        opacity:0;
        background: #87e0fd;
        background: -moz-linear-gradient(top, #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#87e0fd), color-stop(40%,#53cbf1), color-stop(100%,#05abe0));
        background: -webkit-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
        background: -o-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
        background: -ms-linear-gradient(top, #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
        background: linear-gradient(to bottom, #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
    }
    #wrapper:hover:before{opacity:0;}
    #wrapper:hover:after{opacity:1;}
    

提交回复
热议问题