如何在图像中放置矩形并在CSS中为其创建悬停动画?

时间:2015-09-02 09:32:22

标签: html css image

这就是我正在寻找的:

enter image description here

我用html和css裁剪了一个图像,但不知道如何在其中放置矩形。我想动画我应该在div中使用:hovercrop类。 我的代码:http://jsfiddle.net/8t2hmxmn/

1 个答案:

答案 0 :(得分:1)

我想这可以满足您的需求,调整细节元素的高度,只需修改height:

中的.details



html * {
  box-sizing: border-box;
}
.crop {
  background-image: url('http://cs628119.vk.me/v628119319/10059/Ag3oy3YU6wY.jpg');
  width: 200px;
  height: 150px;
  background-position: center;
  background-size: cover;
  position: relative;
  overflow: hidden;
}
.shape {
  width: 200px;
  height: 50px;
  color: black;
}
.details {
  position: absolute;
  bottom: -100%;
  left: 0;
  right: 0;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  padding: 5px 10px;
  transition: all 1s;
  color: white;
}
.crop:hover > .details {
  bottom: 0;
}

<div class="shape">
  <div class="crop">
    <div class="details">
      Yes, this is cat!
    </div>
  </div>
</div>
&#13;
&#13;
&#13;