Hoe te maken: Image overlay icon

Leer hoe je een overlay-image icon effect maakt bij het bladeren met de muis.

Image overlay icon

Plaats de muis over het beeld, om het overlay-effect te zien.

Try it yourself

Hoe een overlay image icon te maken

Stap 1 - Voeg HTML toe:

<!-- 添加图标库 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="container">
  <img src="img_avatar.png" alt="Avatar" class="image">
  <div class="overlay">
    <a href="#" class="icon" title="User Profile">
      <i class="fa fa-user"></i>
    </a>
  </div>
</div>

Second step - Add CSS:

/* Container that needs to be placed for the overlay. Adjust the width as needed */
.container {
  position: relative;
  width: 100%;
  max-width: 400px;
}
/* Make the image responsive */
.image {
  width: 100%;
  height: auto;
}
/* Overlay effect (full height and width) - located at the top of the container and above the image */
.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  width: 100%;
  opacity: 0;
  transition: .3s ease;
  background-color: red;
}
/* The overlay icon fades in when you hover over the container */
.container:hover .overlay {
  opacity: 1;
}
/* Center the icon within the overlay vertically and horizontally */
.icon {
  color: white;
  font-size: 100px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  text-align: center;
}
/* Change color when mouse is over the icon */
.fa-user:hover {
  color: #eee;
}

Try it yourself

Related pages

Tutorial:CSS Image

Tutorial:How to create an image overlay hover effect