麻烦老师检查代码,谢谢
来源:2-9 自由编程
叫我丽红
2021-04-25 15:19:44
<!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>
*{
margin: 0;
padding: 0;
}
.box{
width: 200px;
height: 200px;
overflow: hidden;
position: relative;
}
.box img{
width: 200px;
height: 200px;
}
.box p{
position: absolute;
width: 200px;
height: 20px;
line-height: 20px;
background-color:rgba(0,0,0,.5);
color: white;
text-align: center;
opacity: 0;
bottom:-30px;
transition: bottom 1s linear 0s;
}
.box:hover p{
opacity: 1;
bottom:0px;
}
</style>
</head>
<body>
<div class="box">
<img src="images/cat.jpg" alt="">
<p>这是一只小猫</p>
</div>
</body>
</html>
1回答
好帮手慕星星
2021-04-25
同学你好,测试代码移入的时候有过渡效果,但是移出的时候没有。
这是因为p改变了opacity,而过渡中只写了bottom属性,导致移出的时候突然改变。建议去掉opacity属性的改变,如下:
祝学习愉快!
相似问题