老师麻烦检查一下
来源:2-9 自由编程
qq_慕慕0057983
2022-03-21 20:59:45
<!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>Document</title>
<style>
.box{
width: 500px;
height: 400px;
overflow: hidden;
position:relative;
}
.box img{
width: 500px;
height: 400px;
}
.box p{
position: absolute;
top:400px;
color: white;
font-size: 30px;
font-weight: bold;
height: 100px;
line-height: 90px;
background-color: rgba(0, 0, 0, 0.158);
width: 500px;
transition: top 1s linear 0s;
}
.box:hover p{
top:300px;
}
</style>
</head>
<body>
<div class="box">
<img src="img/duck.png" alt="">
<p>这是一只小黄鸭</p>
</div>
</body>
</html>1回答
好帮手慕慕子
2022-03-22
同学你好,代码实现是正确的,建议优化:添加通配符,去除元素默认的内外边距,效果实现会更美观,示例:

祝学习愉快~
相似问题