DEV Community

Tilak Jain
Tilak Jain

Posted on

3

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 :)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more