How to create an image overlay zoom effect on hover with CSS?

CSSWeb DevelopmentFront End Technology

Following is the code to create an image overlay zoom effect on hover −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.card-container {
   position: relative;
   width: 50%;
}
img {
   display: block;
   width: 100%;
}
.overlay {
   position: absolute;
   top:0;
   bottom: 0;
   left: 0;
   right: 0;
   background-color: rgb(55, 74, 179);
   overflow: hidden;
   width: 100%;
   height: 0;
   transform:scale(0);
   transition: .5s ease-in-out;
}
.card-container:hover .overlay {
   height: 100%;
   transform: scale(1);
}
.caption {
   color: white;
   font-size: 30px;
   position: absolute;
   top: 50%;
   left: 50%;
   text-align: center;
}
</style>
</head>
<body>
<h1>Image Overlay Zoom Example</h1>
<div class="card-container">
<img src="https://i.picsum.photos/id/237/536/354.jpg">
<div class="overlay">
<div class="caption">Dog</div>
</div>
</div>
</body>
</html>

Output

The above code will produce the following output −

On hovering above the image the overlay will zoom and occupy the whole image as follows −

raja
Published on 06-Apr-2020 15:56:03
Advertisements