0

When I put my mouse over it, the background image shows up in an instant. I want to show a gradual trasition. How can I fix this?

.category__mid {
  min-height: 260px;
  width: 200px;
  border: 2px solid #000;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  background-color: rgba(255, 255, 255, 1);
  background-blend-mode: lighten;
  transition: all 0.9s ease;
}

.category__mid:hover {
  background-color: rgba(255, 255, 255, 0);
  background-blend-mode: normal;
}
<div class="category__mid" style="background-image: url('https://i.postimg.cc/NG159gHv/pexels-kampus-production-8439682.jpg')">
  <h3>I want to show transition on hover. NOT when the user leaves</h3>
</div>
manjiro sano
  • 784
  • 3
  • 15
Elaine Byene
  • 3,868
  • 12
  • 50
  • 96
  • Unfortunately you can't use transition on background-image, see the w3c list of animatable properties. - https://www.w3.org/TR/css-transitions-1/#animatable-properties – Luís P. A. Oct 25 '22 at 08:49

2 Answers2

-1

change the css as

.category__mid {
  min-height: 260px;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  background-color: rgba(255,255,255,1);
  background-blend-mode: lighten;
}
.category__mid:hover {
  background-color: rgba(255,255,255,0);
  transition: all 0.9s ease ; 
}
Rishav
  • 1
-1

Change the css to;

.category__mid {
      min-height: 260px;
      width: 200px;
      border: 2px solid #000;
      background-size: cover;
      background-repeat: no-repeat;
      background-position: center;
      background-color: rgba(255,255,255,1);
      background-blend-mode: lighten;
      transition: all 0.9s ease; 
    }
    .category__mid:hover {
      animation: fade-in 0.9s ease;
      background-color: rgba(255,255,255,0);
    }
    
  @keyframes fade-in {
    0% {
      background-blend-mode: lighten;
    }
    100% {
      background-blend-mode: normal;
    }
  }

Unfortunately you can't transition the background image of a div.

but you can use an animation.

Poornaka
  • 180
  • 1
  • 13