老师帮忙看下这样做对不对,有没有冗余代码,哪里需要优化?
来源:2-8 过渡效果实战课(1)
weixin_慕码人7523200
2020-11-04 21:25:02
# 具体遇到的问题
# 报错信息的截图
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 700px;
height: 200px;
margin: 100px auto;
}
.box .box1 {
float: left;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
}
.box .box1+.box1 {
margin-left: 50px;
}
.box .box1 img {
width: 200px;
height: 200px;
}
.box .box1 span:nth-of-type(1) {
position: absolute;
bottom: 0;
width: 200px;
height: 30px;
background: #000;
color: white;
text-align: center;
line-height: 30px;
opacity: 0;
transition: opacity 1s linear 0s;
}
.box .box1:hover span:nth-of-type(1) {
opacity: 1;
}
.box .box1 span:nth-of-type(2) {
position: absolute;
top: -30px;
width: 200px;
height: 30px;
background: #000;
color: white;
text-align: center;
line-height: 30px;
transition: top .5s linear 0s;
}
.box .box1:hover span:nth-of-type(2) {
top: 0;
}
</style>
</head>
<body>
<div class="box">
<div class="box1">
<span>我是底部淡入文字</span>
<span>我是顶部hidden文字</span>
<img src="../images/03-04.jpg" alt="">
</div>
<div class="box1">
<span>我是底部淡入文字</span>
<span>我是顶部hidden文字</span>
<img src="../images/news_pic.png" alt="">
</div>
<div class="box1">
<span>我是底部淡入文字</span>
<span>我是顶部hidden文字</span>
<img src="../images/cos.jpg" alt="">
</div>
</div>
</body>
</html>
1回答
同学你好,代码实现正确,也挺简洁,不用修改了。祝学习愉快~
相似问题