【问题标题】:React JS edit image overlay on img html tagReact JS在img html标签上编辑图像覆盖
【发布时间】:2019-02-27 00:19:29
【问题描述】:

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

【问题讨论】:

    标签: html css reactjs


    【解决方案1】:

    这是一个例子:

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

    【讨论】:

    • 这实际上只是把它放在img下面
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      • 2014-09-29
      • 2011-11-18
      • 2021-07-03
      相关资源
      最近更新 更多