【问题标题】:show caption on image when hover [duplicate]悬停时在图像上显示标题[重复]
【发布时间】:2017-02-19 22:31:52
【问题描述】:

当有人将鼠标悬停在图像上时,我正在尝试显示标题。但我找不到完成这项工作的方法。

我正在使用 Twitter Bootstrap

这是我其中一张图片的 HTML。我不知道如何将内容放入其中,以便仅在有人将鼠标悬停在其上时才显示。

  <div class="col-lg-2 col-md-3 col-sm-4 col-xs-12 thumb">
        <a class="thumbnail caption-style-1 model-thumbnail " href="#">
          <img class="img-responsive" src="http://placehold.it/245x347" alt>
        </a>
  </div>

Bootply

【问题讨论】:

    标签: html css


    【解决方案1】:

    这是一个受this website启发的很酷的例子。

    ul.img-list {
      text-align: center;
    }
    
    ul.img-list li {
      display: inline-block;
      height: 150px;
      position: relative;
      width: 150px;
    }
    
    span.text-content span {
      display: table-cell;
      text-align: center;
      vertical-align: middle;
    }
    
    span.text-content {
      background: rgba(0,0,0,0.5);
      color: white;
      display: table;
      height: 150px;
      left: 0;
      position: absolute;
      top: 0;
      width: 150px;
      opacity: 0;
    }
    
    ul.img-list li:hover span.text-content {
      opacity: 1;
    }
    <ul class="img-list">
      <li>
          <img src="http://placehold.it/150x150"/>
          <span class="text-content"><span>1st image</span></span>
      </li>
        <li>
          <img src="http://placehold.it/150x150"/>
          <span class="text-content"><span>2nd image</span></span>
      </li>
        <li>
          <img src="http://placehold.it/150x150"/>
          <span class="text-content"><span>3rd image</span></span>
      </li>
    </ul>

    【讨论】:

      【解决方案2】:

      div {width: 245px; height: 245px;}
      a {position: relative; display: inline-block;}
      a + span {display: none; position: absolute; top: 0; left: 0; bottom: 0; right: 0;  background: rgba(0,0,0,0.5);}
      a:hover + span {display: block; pointer-events: none;}
      <div class="col-lg-2 col-md-3 col-sm-4 col-xs-12 thumb">
        <a class="thumbnail caption-style-1 model-thumbnail " href="#">
          <img class="img-responsive" src="http://placehold.it/245x347" alt>
        </a>
        <span>Text</span>
      </div>

      【讨论】:

        猜你喜欢
        • 2019-03-14
        • 2016-03-17
        • 2014-05-14
        • 2014-03-28
        • 1970-01-01
        • 1970-01-01
        • 2019-06-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多