Overlay Zoom Effect on Hover Using HTML & CSS
An overlay zoom effect on hover makes images more interactive and stylish. This effect is achieved using CSS transformations and opacity.
Step 1: HTML Code
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Overlay Zoom Effect on Hover</title>
<meta name="description" content="Learn how to create an overlay zoom effect on hover using HTML and CSS. A stylish zoom animation for images with a semi-transparent overlay.">
<meta name="keywords" content="hover zoom effect, CSS overlay zoom, image hover effect, CSS zoom animation, image transition effect">
</head>
<body>
<h2>Image Hover Fullscreen Zoom</h2>
<p>Hover over the image to see the zoom effect.</p>
<div class="container">
<img src="img_avatar.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</body>
</html>
Step 2: CSS Code
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
body {
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 100%;
-webkit-transform: scale(0);
-ms-transform: scale(0);
transform: scale(0);
-webkit-transition: .3s ease;
transition: .3s ease;
}
.container:hover .overlay {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
How It Works
- Initially, the overlay is hidden (
scale(0);). - When the user hovers over the image, the
.overlayscales up to full size (scale(1)), covering the image. - The text appears centered inside the overlay.