Simple CSS transition - nothing working

前端 未结 1 813
一生所求
一生所求 2021-01-21 08:25

I am working on an image with a gradient that disappears on hover. However, I can\'t get this to transition. I\'ve tried every webkit transition that I know of and it doesn\'t s

相关标签:
1条回答
  • 2021-01-21 08:42

    You cannot apply transition on gradient, you may try to add transition on background-size. Use different value of background-size to adjust the way the transtion will work and you can also change the background-position:

    .tinted-image {
      -webkit-transition: all .7s ease;
      transition: all .7s ease;
      position: relative;
      width: 100%;
      padding-top: 56.25%;
      /* 16:9 Aspect Ratio */
      border-radius: 10px;
      background: linear-gradient( rgba(255, 0, 0, 0.6), rgba(237, 240, 0, 0.6)),
      /* image */
      url(http://calvarygigharbor.com/wp-content/uploads/2018/05/church-softball-2018.jpg);
      background-size:100% 100%, contain;
      background-position:center,center; /*OR [left,center] OR [top,center] ...*/ 
      background-repeat:no-repeat;
    }
    
    .tinted-image:hover {
      -webkit-transition: all .7s ease;
      transition: all .7s ease;
      position: relative;
      width: 100%;
      padding-top: 56.25%;
      /* 16:9 Aspect Ratio */
      border-radius: 10px;
      background-size:0 0,contain; /* OR [100% 0,contain] OR [0 100%,contain] */
    }
    <a href="http://calvarygigharbor.com/heavenly-hitters/">
      <div class="tinted-image"> </div>
    </a>

    0 讨论(0)
提交回复
热议问题