How to create image overlay hover effect with CSS?

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


 Live Demo

<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">
.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;
<h1>Image Overlay effect Example</h1>
<div class="card-container">
<img src="">
<div class="hoverText">
<div class="caption">Dog</div>


The above code will produce the following output −

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