DEV Community

Tilak Jain
Tilak Jain

Posted on

Make an Image Hover Overlay using html and css

You may have made a Profile Card. But, what if there was a card on which when we hover; it shows us some content!

Now that is possible only by using css.

Today we are going to make something like above mentioned.

Let us get started:

Step 1: HTML

<div class="container">
  <img src="your_pic.png" alt="text" class="image">
  <div class="overlay">
    <div class="text">Good Day</div>
  </div>
</div>
Enter fullscreen mode Exit fullscreen mode

Step 2: CSS

.container {
  position: relative;
  width: 50%;
}

.image {
  display: block;
  width: 100%;
  height: auto;
}

.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  width: 100%;
  opacity: 0;
  transition: .5s ease;
  background-color: crimson;/* U can choose your favourite color */
}

.container:hover .overlay {
  opacity: 1;
}

.text {
  color: white;
  font-family: sans-serif;
  font-size: 25px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  text-align: center;
}
Enter fullscreen mode Exit fullscreen mode

Now, you have successfully made your first Image Hover Overlay Card.
This is it for today! Bye :)

Top comments (0)