Gooby
Gooby

Reputation: 733

React JS edit image overlay on img html tag

similar to facebook a img tag to function like when you hover over your profile picture and this little overlay goes on top asking if you want to edit photo. I have the hover working but I don't know how to get the overlay. I'm using img tag cause the image is from a URL

Upvotes: 5

Views: 6660

Answers (2)

Soroush Chehresa
Soroush Chehresa

Reputation: 5678

Here is an example:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.container {
    position: relative;
    width: 50%;
}

.image {
  opacity: 1;
  display: block;
  width: 100%;
  height: auto;
  transition: .5s ease;
  backface-visibility: hidden;
}

.middle {
  transition: .5s ease;
  opacity: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  text-align: center;
}

.container:hover .image {
  opacity: 0.3;
}

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

.text {
  background-color: #4CAF50;
  color: white;
  font-size: 16px;
  padding: 16px 32px;
}
</style>
</head>
<body>

<div class="container">
  <img src="https://www.w3schools.com/howto/img_avatar.png" alt="Avatar" class="image" style="width:100%">
  <div class="middle">
    <div class="text">John Doe</div>
  </div>
</div>
  
</body>
</html>

reference: w3schools

Upvotes: 3

Konda
Konda

Reputation: 78

Here is a good example of overlays on images - https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_opacity

Upvotes: 0

Related Questions