HTML悬停图像:扩大可点击区域超过图像
P粉459440991
P粉459440991 2023-09-10 16:08:26
0
1
659

我对css/html相对较新。 我已经浏览了一段时间关于这个问题,但没有找到解决办法。

问题是,如果我使用下面的代码(使用Bulma),当在img3.jpg悬停时,可点击区域是从第一个

开始的整个块。我怀疑问题可能是Bulma的is-column / is-multiline之间的冲突,以及我提供的覆盖CSS定义

<style type="text/css">
  ul {
    list-style: none;
    padding: 10px 10px 10px 30px
  }
  ul li {
    font-size: 120%;
    margin-left: 10px;
    list-style-type: circle;
  }
</style>

<style>
.container {
  position: relative;
  width: 100%;
}

.image {
  display: block;
  width: 100%;
  height: auto;
}

.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100%;
  width: 100%;
  opacity: 0;
  transition: .5s ease;
  background-color: #008CBA;
}

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

.text {
  color: white;
  font-size: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  text-align: center;
}
</style>

<div class="columns is-multiline">
  <div class="column is-9">
    <div class="content">
      <h3> 关于我们 </h3>
      <hr>
      <p align="left" style="font-size:120%;">
        一些内容...
      </p>
    </div>
    <div class="columns is-multiline">
      <div class="column is-4">
          <img src="/images/img1.jpg" alt="" class="image"/>
      </div>
      <div class="column is-4">
          <img src="/images/img2.jpg" alt="" class="image"/>
      </div>
      <div class="column is-4">
        <div class="container">
          <img src="/images/img3.jpg" alt="" class="image"/>
          <div class="overlay">
            <div class="text">你好,世界</div>
          </div>
        </div>
      </div>
    </div>

    <p align="left" style="font-size:120%;">
      一些文本...

      <ul>
        <li>
          项目1
          <a href="url1">
             <b>链接</b>
          </a>
        </li>
        <li>
          项目2
          <a href="url2">
             <b>链接</b></a>
        </li>
      </ul>
    </p>

  </div>

  <div class="column is-3">
    {% include latest-posts.html %}
  </div>
</div>
<hr>
P粉459440991
P粉459440991

全部回复(1)
P粉738346380

尝试这个文档

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
  <title>Document</title>
  <style>
    body {
      padding-top: 2em;
    }
    
    ul {
      list-style: none;
      padding: 10px 10px 10px 30px
    }
    
    ul li {
      font-size: 120%;
      margin-left: 10px;
      list-style-type: circle;
    }
    
    .container {
      position: relative;
      width: 100%;
    }
    
    .columns {
      display: flex;
    }
    
    .image {
      display: block;
      width: 100%;
      max-width: 320px;
      height: auto;
    }
    
    .overlay {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      height: 100%;
      width: 100%;
      opacity: 0;
      transition: .5s ease;
      background-color: #008CBA;
    }
    
    .container:hover .overlay {
      opacity: 1;
    }
    
    .text {
      color: white;
      font-size: 20px;
      position: absolute;
      top: 50%;
      left: 50%;
      -webkit-transform: translate(-50%, -50%);
      -ms-transform: translate(-50%, -50%);
      transform: translate(-50%, -50%);
      text-align: center;
    }
    
    .test {
      position: absolute;
      left: 0;
      border-bottom: green solid;
      font-size: .5em;
      font-weight: bold;
    }
    
    .test-top {
      top: 0;
    }
    
    .test-bottom {
      bottom: 0;
    }
  </style>
</head>

<body>

  <div class="columns is-multiline">
    <div class="column is-9">
      <div class="content">
        <h3> 关于我们 </h3>
        <hr>
        <p style="font-size:120%; text-align:left">
          一些内容...
        </p>
      </div>
      <div class="columns is-multiline">
        <p class="test test-top">开始 columns / is-multiline</p>
        <div class="column is-4">
          <img src="https://w7.pngwing.com/pngs/715/287/png-transparent-number-1-number-1-creative-cartoon-thumbnail.png" alt="" class="image" />
        </div>
        <div class="column is-4">
          <img src="https://w7.pngwing.com/pngs/664/223/png-transparent-number-2-number-number-2-image-file-formats-text-heart-thumbnail.png" alt="" class="image" />
        </div>
        <div class="column is-4">
          <div class="container">
            <img src="https://w7.pngwing.com/pngs/111/727/png-transparent-number-3-illustration-number-blue-crystal-number-three-teal-number-symbol-thumbnail.png" alt="" class="image" />
            <div class="overlay">
              <p class="test test-top">开始覆盖</p>
              <div class="text">你好世界</div>
              <p class="test test-bottom">结束覆盖</p>
            </div>
          </div>
        </div>
        <p class="test test-bottom">结束 columns / is-multiline</p>
      </div>

      <p style="font-size:120%; text-align:left">
        一些文本...

        <ul>
          <li>
            项目1
            <a href="url1">
              <b>链接</b>
            </a>
          </li>
          <li>
            项目2
            <a href="url2">
              <b>链接</b></a>
          </li>
        </ul>
      </p>

    </div>

    <div class="column is-3">
      {% include latest-posts.html %}
    </div>
  </div>
  <hr>

</body>

</html>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!