图片显示悬停时的文字为"翻转"

时间:2015-04-29 14:43:48

标签: html css css3 hover css-transitions

我想制作一个"滚动文字"当您将鼠标悬停在图像容器上时。

我做得很好,但只有位置绝对,但我不能正确的位置相对。

现在文字出现在图像之后,但我需要将文本作为图像底部的小叠加

<div class="ce_image team block">
  <figure class="image_container">
    <img src="assets/images/c/De****-D1-6a7e730c.jpg" width="300" height="300" alt="">
          <figcaption class="caption" style="width:300px">The text i want to display on hover</figcaption> 
  </figure>
</div>

css :( ps:我觉得我的CSS非常糟糕,从来没有像这样做过)

   .image_container {
      position: relative;
      display: inline-block;
      padding: 0.75em;
      border: 1px solid #b2b9c4;
      border-radius: 2px;
      background: #ffffff;
      background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
      background-image: -moz-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
      background-image: -o-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
      background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
      box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
    }
    .team .image_container figcaption, .team .image_container .caption {
      width: 100% !important;
      padding: 0.42857em 0 0;
      font-size: 1.0em;
      display: none !important;
      display: fixed;
      color: #000000;
      font-weight: bold;
      position: static !important;
      text-align: center;
      top: 100px;
      z-index: 999;
      opacity: 0;
      transition: opacity 0.2s linear !important;
      left: 0px;
      background: rgba(255, 255, 255, 0.9);
      position: relative;
    }

.team .image_container:hover figcaption, .team .image_container:hover .caption {
  width: 100% !important;
  padding: 0.42857em 0 0;
  font-size: 1.0em;
  color: #000000;
  font-weight: bold;
  text-align: center;
  top: -31px;
  z-index: 999;
  opacity: 1;
  left: 0px;
  background: rgba(255, 255, 255, 0.9);
  position: relative;
  display: block !important;
}

在这里摆弄css:

https://jsfiddle.net/vm73gfhn/

1 个答案:

答案 0 :(得分:1)

我更新了一些CSS,以便文本位于底部。你需要绝对位置而不是位置相对:

    .image_container {
  position: relative;
  display: inline-block;
  padding: 0.75em;
  border: 1px solid #b2b9c4;
  border-radius: 2px;
  background: #ffffff;
  background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
  background-image: -moz-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
  background-image: -o-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
  background-image: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.02));
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.team .image_container figcaption, .team .image_container .caption {
  display: none !important;
}

.team .image_container:hover figcaption, .team .image_container:hover .caption {
  width: 100% !important;
  padding: 0.42857em 0 0;
  font-size: 1.0em;
  color: #000000;
  font-weight: bold;
  text-align: center;
  bottom: 0px;
  z-index: 999;
  opacity: 1;
  left: 0px;
  background: rgba(255, 255, 255, 0.9);
  position: absolute;
  display: block !important;
}

JSFIDDLE

其他

如果您希望它适用于移动设备和平板电脑,请使用媒体查询: http://www.w3schools.com/cssref/css3_pr_mediaquery.asp