从背景图片下方过渡文字

时间:2018-11-12 09:35:36

标签: html css transition

问题: 我不知道如何在每个人的个人资料图片中做出不错的hover/transition

当有人将鼠标悬停在图片圆圈上时,我希望该人的其他信息从下方出现/滑入。

https://i.imgur.com/FMEVDx9.jpg

我正在将一个关于我们的页面作为学校项目。正在考虑可能是一些z-index欺骗或不透明。

1 个答案:

答案 0 :(得分:0)

.container {
  position: relative;
  width: 50%;
}

.image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 50%;
}

.overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: hidden;
  width: 100%;
  height: 0;
  transition: .5s ease;
}

.container:hover .overlay {
  height: 100%;
}

.text {
  color: white;
  font-size: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  text-align: center;
}
<body>

<p>Hover over the image to see the effect.</p>

<div class="container">
  <img src="https://upload.wikimedia.org/wikipedia/en/thumb/1/17/Batman-BenAffleck.jpg/200px-Batman-BenAffleck.jpg" alt="Avatar" class="image">
  <div class="overlay">
    <div class="text">Hi I'm Batman</div>
  </div>
</div>

</body>
</html>

  

尝试以下方法。我想这就是您要寻找的。我为此使用了纯CSS。悬停时,文本从底部升起。我使用了overlay类,并使用了图像的边界半径来获取您想要的圆形。

您可以了解有关这些技巧的更多信息here.