Use CSS3 transitions with gradient backgrounds

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

    I wanted to have a div appear like a 3D sphere and transition through colors. I discovered that gradient background colors don't transition (yet). I placed a radial gradient background in front of the element (using z-index) with a transitioning solid background.

    /* overlay */
    z-index : 1;
    background : radial-gradient( ellipse at 25% 25%, rgba( 255, 255, 255, 0 ) 0%, rgba( 0, 0, 0, 1 ) 100% );
    

    then the div.ball underneath:

    transition : all 1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    

    then changed the background color of the div.ball and voila!

    https://codepen.io/keldon/pen/dzPxZP

提交回复
热议问题