【问题标题】:Responsive image hover caption响应式图像悬停标题
【发布时间】:2016-12-19 10:23:04
【问题描述】:

我面临的问题是悬停标题.caption-text 和覆盖.blur 是固定的宽度和高度,而图像是响应式的。

关于如何修改此代码以使叠加层和标题适合图像宽度和高度的任何建议?

.caption-style-4 {
  list-style-type: none;
  margin: 0px;
  padding: 0px;
}
.caption-style-4 li {
  float: left;
  padding: 0px;
  position: relative;
  overflow: hidden;
}
.caption-style-4 li:hover .caption {
  opacity: 1;
}
.caption-style-4 li:hover img {
  opacity: 1;
  transform: scale(1.15, 1.15);
  -webkit-transform: scale(1.15, 1.15);
  -moz-transform: scale(1.15, 1.15);
  -ms-transform: scale(1.15, 1.15);
  -o-transform: scale(1.15, 1.15);
}
.caption-style-4 img {
  margin: 0px;
  padding: 0px;
  float: left;
  z-index: 4;
}
.caption-style-4 .caption {
  cursor: pointer;
  position: absolute;
  opacity: 0;
  -webkit-transition: all 0.45s ease-in-out;
  -moz-transition: all 0.45s ease-in-out;
  -o-transition: all 0.45s ease-in-out;
  -ms-transition: all 0.45s ease-in-out;
  transition: all 0.45s ease-in-out;
}
.caption-style-4 img {
  -webkit-transition: all 0.25s ease-in-out;
  -moz-transition: all 0.25s ease-in-out;
  -o-transition: all 0.25s ease-in-out;
  -ms-transition: all 0.25s ease-in-out;
  transition: all 0.25s ease-in-out;
}
.caption-style-4 .blur {
  background-color: rgba(0, 0, 0, 0.65);
  height: 300px;
  width: 400px;
  z-index: 5;
  position: absolute;
}
.caption-style-4 .caption-text h1 {
  text-transform: uppercase;
  font-size: 24px;
}
.caption-style-4 .caption-text {
  z-index: 10;
  color: #fff;
  position: absolute;
  width: 400px;
  height: 300px;
  text-align: center;
  top: 100px;
}
<div class="container-a4">
  <ul class="caption-style-4">
    <li>
      <img src="http://lorempixel.com/output/abstract-q-c-600-480-1.jpg" alt="">
      <div class="caption">
        <div class="blur"></div>
        <div class="caption-text">
          <h1>Amazing Caption</h1>
          <p>Whatever It Is - Always Awesome</p>
        </div>
      </div>
    </li>
  </ul </div>

http://codepen.io/anon/pen/GNzMNV

【问题讨论】:

  • 请您包含您编译的 HTML 而不是 PHP,以便我们重现您的问题。扫描一下,这很可能是由于您使用了绝对定位。
  • 我认为这是因为绝对位置,因为没有 w/h 来强制打开 div。如果可能的话,寻找可以帮助我解决这个问题的建议/教程链接
  • 我应该能够提供帮助,但要做到这一点,我需要一个可重现的示例。请修改您的问题,我会看看我能做些什么!
  • 只需放入一个codepen - 有帮助吗?

标签: html css css-transitions


【解决方案1】:

只需更新你的 CSS

.caption-style-4 .caption-text {
    z-index: 10;
    color: #fff;
    position: absolute;
    width: 100%;
    height: 95px;
    text-align: center;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
}
.caption-style-4 .blur {
    background-color: rgba(0,0,0,0.65);
    height: 100%;
    width: 100%;
    z-index: 5;
    position: absolute;
}
.caption-style-4 .caption {
    cursor: pointer;
    position: absolute;
    opacity: 0;
    -webkit-transition: all 0.45s ease-in-out;
    -moz-transition: all 0.45s ease-in-out;
    -o-transition: all 0.45s ease-in-out;
    -ms-transition: all 0.45s ease-in-out;
    transition: all 0.45s ease-in-out;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
}

这是更新后的代码笔http://codepen.io/anon/pen/MbLEXr

如果它仍然不起作用,请告诉我。

【讨论】:

    【解决方案2】:

    您可以包含 jquery.js 并计算图像的宽度、高度。 也添加到 css .singlePillar .caption {top:0px;} 例子: https://jsfiddle.net/hc2tr7s3/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-30
      • 1970-01-01
      • 2013-12-03
      • 2016-01-18
      • 1970-01-01
      • 1970-01-01
      • 2014-02-12
      • 1970-01-01
      相关资源
      最近更新 更多