实现视频中说到的悬停效果:鼠标悬停,升起一个遮罩,半透明,上面有文字;然后浮现一个播放按钮。提示:用div做个容器,把原图、遮罩以a元素放于其中。遮罩里面放文字,半透明,置于容器bottom,高度height为0 ,鼠标悬停时,transition height变到和原图一样高即可;把握好transition的时间,延迟播放按钮的显示,让其和遮罩配合,达到遮罩升到位的时候,按钮显示的效果。写出其html和css代码
时间: 2024-03-03 21:51:53 浏览: 200
好的,这是实现悬停效果的HTML和CSS代码:
HTML代码:
```
<div class="container">
<a href="#">
<img src="your-image-url" alt="your-image-description">
<div class="mask">
<p>your-text-description</p>
<button class="play-btn">Play</button>
</div>
</a>
</div>
```
CSS代码:
```
.container {
position: relative;
}
.container img {
display: block;
}
.container a {
display: block;
}
.container .mask {
position: absolute;
bottom: 0;
width: 100%;
height: 0;
background-color: rgba(0, 0, 0, 0.5);
transition: height 0.3s ease-in-out;
}
.container a:hover .mask {
height: 100%;
}
.container .mask p {
color: #fff;
font-size: 16px;
text-align: center;
margin: 0;
padding: 20px;
}
.container .mask .play-btn {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 10px 20px;
background-color: #fff;
color: #000;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
.container a:hover .mask .play-btn {
display: block;
transition: all 0.3s ease-in-out;
}
```
上述代码中,我们用了一个div作为容器,里面包含了一张图片、一个遮罩和一个播放按钮。我们给容器设置了position: relative,然后给遮罩设置position: absolute和bottom: 0,使其置于容器底部。初始时,遮罩的高度为0,当鼠标悬停在容器上时,遮罩的高度将会过渡到和原图一样高,同时播放按钮也会浮现出来。此外,我们还用了CSS3的transition属性,让遮罩高度过渡时有一个平滑的动画效果。
阅读全文
相关推荐


















