功能要求:
- 实现当鼠标悬浮时显示底部文字,反之移走鼠标文字褪去
图片示例
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/79e3121ec098b19c54d46d17cef961fb.png)
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>过渡效果实战1</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
width: 1200px;
overflow: hidden;
margin: 40px auto;
}
.box ul {
list-style: none;
}
.box ul li {
width: 380px;
height: 210px;
float: left;
margin-right: 20px;
position: relative;
}
.box ul li img {
width: 380px;
height: 210px;
}
.box ul li p {
position: absolute;
width: 380px;
height: 30px;
line-height: 30px;
color: white;
bottom: 0;
text-align: center;
background-color: rgba(0, 0, 0, .5);
opacity: 0;
transition: opacity 1s ease 0s;
}
.box ul li:hover .info{
opacity: 1;
}
</style>
</head>
<body>
<div class="box">
<ul>
<li>
<img src="../images/1.jpg">
<p class="info">北京的故宫</p>
</li>
<li>
<img src="../images/2.jpg">
<p class="info">鸟巢国家体育场</p>
</li>
<li>
<img src="../images/3.jpg">
<p class="info">十七孔桥</p>
</li>
</ul>
</div>
</body>
</html>