Use CSS3 transitions with gradient backgrounds

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

    A solution is to use background-position to mimic the gradient transition. This solution was used in Twitter Bootstrap a few months ago.

    Update

    http://codersblock.blogspot.fr/2013/12/gradient-animation-trick.html?showComment=1390287622614

    Here is a quick example:

    Link state

     .btn {
      font-family: "Helvetica Neue", Arial, sans-serif;
      font-size: 12px;
      font-weight: 300;
      position: relative;
      display: inline-block;
      text-decoration: none;
      color: #fff;
      padding: 20px 40px;
      background-image: -moz-linear-gradient(top, #50abdf, #1f78aa);
      background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#50abdf), to(#1f78aa));
      background-image: -webkit-linear-gradient(top, #50abdf, #1f78aa);
      background-image: -o-linear-gradient(top, #50abdf, #1f78aa);
      background-image: linear-gradient(to bottom, #50abdf, #1f78aa);
      background-repeat: repeat-x;
      filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff50abdf', endColorstr='#ff1f78aa', GradientType=0);
      background-repeat: repeat-y;
      background-size: 100% 90px;
      background-position: 0 -30px;
      -webkit-transition: all 0.2s linear;
         -moz-transition: all 0.2s linear;
           -o-transition: all 0.2s linear;
              transition: all 0.2s linear;
    }
    

    Hover state

    .btn:hover {
       background-position: 0 0;
    }
    

提交回复
热议问题