Amazing css with hover effect on image

Posted on October 24th, 2019

This is an amazing css with hover effect on image by html and css only from DarkCode. Just click on the button Run Pen to see how it works:

How to create an amazing css with hover effect on image

Step 1: Add Html

<div class="image middle">
  <img
    src="https://res.cloudinary.com/drcrre4xg/image/upload/v1571848483/img_gfo5ks.jpg"
    alt=""
  />
  <div class="image-content">
    <h1>Image Title</h1>
    <div class="icons">
      <a href="#" class="icon fas fa-heart"></a>
      <a href="#" class="icon fas fa-comment"></a>
      <a href="#" class="icon fas fa-share"></a>
    </div>
  </div>
</div>

Step 2: Add CSS

* {
  margin: 0;
  padding: 0;
  font-family: 'montserrat';
}
body {
  background: #ddd;
}
.middle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.image {
  width: 440px;
  height: 300px;
  overflow: hidden;
  cursor: pointer;
}

.image-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 40px;
  box-sizing: border-box;
}
.image-content h1 {
  color: #fff;
  text-transform: uppercase;
  transform: translateY(20px);
  transition: 0.4s;
}
.image:hover .image-content h1 {
  transform: translateY(0px);
}
.icons {
  position: absolute;
  right: 40px;
  bottom: 40px;
}
.icon {
  text-decoration: none;
  color: #333;
  font-size: 22px;
  margin: 0 10px;
  transform: translateY(80px);
}
.image:hover .icon {
  transform: translateY(0px);
}
.icon:nth-child(1) {
  transition: transform 0.4s 0.05s, color 0.4s;
}
.icon:nth-child(2) {
  transition: transform 0.4s 0.1s, color 0.4s;
}
.icon:nth-child(3) {
  transition: transform 0.4s 0.15s, color 0.4s;
}
.icon:hover {
  color: #3498db;
}
.image-content::before {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.7);
  width: 100%;
  height: 0px;
  clip-path: polygon(0 100%, 100% 0, 100% 100%);
  transition: 0.5s;
}
.image-content:hover::before {
  height: 140px;
}