React JS编辑图像叠加在img html标签上

时间:2018-09-23 05:15:55

标签: html css reactjs

类似于facebook的img标签,其功能类似于将鼠标悬停在个人资料图片上时,上面的这个小叠图会询问您是否要编辑照片。我有悬停工作,但我不知道如何获取覆盖。我正在使用img标签,因为图像来自URL

2 个答案:

答案 0 :(得分:3)

这里是一个例子:

<!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>

参考:w3schools

答案 1 :(得分:0)