【发布时间】:2019-10-27 12:16:08
【问题描述】:
我有一些在图像上标有名称和标题的员工图块。在鼠标悬停时,我希望图像稍微缩放,文本从图像上滑落。我已经能够制作所有动画,但是当文本从图像上滑落时,我无法隐藏它。
我尝试了overflow: hidden 的各种变体,并弄乱了white-space 和text-overflow,但没有运气。
我在这里创建了一个 CodePen:https://codepen.io/iisrael/pen/EBjmPW
这里是 HTML
<div class="speaker-tile-grid">
<div class="speaker-tile">
<img src="https://cdn.pixabay.com/photo/2016/06/09/20/38/woman-1446557_960_720.jpg" width="300px" height="300px">
<h3>Person #1</h3>
<h4>They do stuff</h4>
</div>
</div>
这是 CSS:
.speaker-tile-grid {
display: grid;
grid-template-columns: repeat(auto-fit,minmax(200px, 300px));
grid-template-rows: repeat(auto-fit,minmax(200px, 300px));
grid-gap: 1em;
margin: 0;
}
.speaker-tile {
overflow: hidden!important;
}
.speaker-tile img {
transition: 750ms;
}
.speaker-tile:hover img {
transform: scale(1.05);
}
.speaker-tile h3 {
position: absolute;
bottom: 45px;
background-color: #ff6600;
color: white;
padding: 5px 10px 10px 10px;
transition: 750ms;
}
.speaker-tile:hover h3 {
transform: translateX(-100%);
}
.speaker-tile h4 {
position: absolute;
bottom: 25px;
background-color: #313131;
color: white;
padding: 4px 10px;
transition: 750ms;
}
.speaker-tile:hover h4 {
transform: translateX(-100%);
}
我需要知道如何在文本离开图像时隐藏它。 text-overflow: Clip 或 overflow: hidden 或其他东西,因为这些对我不起作用。非常感谢任何帮助。
【问题讨论】: