html - CSS 图像标题悬停与过渡

标签 html css css-transitions zurb-foundation

我一直在尝试实现类似于此的 CSS 图像悬停 example .我无法让悬停包含在我的图像中。 hover screenshot

可能很重要的一点是,我使用的是 Zurb Foundation 和“large-block-grid”类。干杯。

我的 HTML:

<div class="recent-work">
  <div class="row">
    <div class="large-12 columns">
      <ul class="large-block-grid-2">
        <li>
         <a href="#">
           <div class="caption"><span>First Image Hover</span></div>
           <img src="http://hhhhold.com/577x577">
         </a>
         </li>
         <li>
          <a href="#">
            <div class="caption"><span>Second Image Hover</span></div>
            <img src="http://hhhhold.com/577x577">
          </a>
         </li>
      </ul>
    </div>
  </div>
</div><!-- End recent-work -->

我的 CSS:

.recent-work {
  margin: 0 0 50px;
}

// Img hovers

.caption span {
  top: 50%; 
}

ul.large-block-grid-2 .caption {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  text-align: center;
  opacity: 0;
  background-color: rgba(245, 64, 77, 0.75);
  background-color: rgba(245, 64, 77, 0.25);
  background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(245, 64, 77, 0.25)), color-stop(100%, #f5404d));
  background-image: -webkit-linear-gradient(rgba(245, 64, 77, 0.25), #f5404d);
  background-image: linear-gradient(rgba(245, 64, 77, 0.25), #f5404d);
  -webkit-transition: all 0.2s linear;
  -moz-transition: all 0.2s linear;
  transition: all 0.2s linear;
  -webkit-transform: translate3d(0, 0, 0); 
}

ul.large-block-grid-2 .caption span {
  padding: 1rem;
  position: relative;
  top: 52%;
  opacity: 0;
  color: white;
  text-transform: uppercase;
  letter-spacing: 1px;
  -webkit-transition: all 0.4s ease;
  -moz-transition: all 0.4s ease;
  transition: all 0.4s ease;
}

ul.large-block-grid-2 a:hover .caption {
  opacity: 1;
}

ul.large-block-grid-2 a:hover .caption span {
  top: 48%;
  opacity: 1;
}

最佳答案

这是一个 Fiddle

img {
  width: 100%;
  height: 100%;
}
ul li {
  list-style: none;
  float: left;
  width: 400px;
  height: 400px;
  margin: 0 10px 10px 0;
}

ul.large-block-grid-2 .caption {
  position: absolute;
  display: inherit;
  width: 400px;
  height: 400px;
  text-align: center;
  opacity: 0;
  background-color: rgba(245, 64, 77, 0.75);
  background-color: rgba(245, 64, 77, 0.25);
  background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(245, 64, 77, 0.25)), color-stop(100%, #f5404d));
  background-image: -webkit-linear-gradient(rgba(245, 64, 77, 0.25), #f5404d);
  background-image: linear-gradient(rgba(245, 64, 77, 0.25), #f5404d);
  -webkit-transition: all 0.2s linear;
  -moz-transition: all 0.2s linear;
  transition: all 0.2s linear;
  -webkit-transform: translate3d(0, 0, 0); 
}

关于html - CSS 图像标题悬停与过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18839967/

相关文章:

html - 文本对齐 - CSS 还是 HTML?

javascript - 使用 window.location.href 后没有输出到 iframe

css - CSS 中的 float 问题

css - 如何在我的 ASP 应用程序中也包含 Bootstrap 字体目录?

html - 需要帮助获得文本内容的平滑 CSS 过渡

javascript - 寻找同级的多重选择器

javascript - javascript 通过下拉列表在音频之间切换

html - 比较同一网站的两个版本

html - 在不移动 div 的情况下放大 div 内的图像

jquery - 当用户将鼠标悬停在图像上时,如何获得图像的缩放效果?