How to create image overlay hover effect with CSS?

CSSWeb DevelopmentFront End Technology

Following is the code to produce bottom navigation menu with CSS −

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.card-container {
   display: inline-block;
   position: relative;
   width: 50%;
}
img {
   opacity: 1;
   display: block;
   width: 100%;
   transition: .5s ease;
   backface-visibility: hidden;
}
.hoverText {
   transition: .5s ease;
   opacity: 0;
   position: absolute;
   top: 50%;
   left: 40%;
   text-align: center;
}
.card-container:hover img {
   opacity: 0.4;
}
.card-container:hover .hoverText {
   opacity: 1;
}
.caption {
   background-color: rgb(18, 53, 131);
   color: white;
   font-size: 30px;
   padding: 20px;
   border-radius: 6px;
   font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
   font-weight: bolder;
}
</style>
</head>
<body>
<h1>Image Overlay effect Example</h1>
<div class="card-container">
<img src="https://i.picsum.photos/id/237/536/354.jpg">
<div class="hoverText">
<div class="caption">Dog</div>
</div>
</div>
</body>
</html>

Output

The above code will produce the following output −

On hovering above the image the caption will be shown as follows −

raja
Published on 06-Apr-2020 15:50:36
Advertisements