在很多电商网站,会存在商品的展示,当用户把鼠标移入商品图片上时,会从上面滑下商品的详情,价格等文字,来实现这个小案例
案例展示
代码实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
* {
margin: 0;padding: 0;
}
#box {
width: 200px;height: 200px;
background: rgb(133, 120, 101);
position: relative;
margin-left: 400px;margin-top: 120px;
overflow: hidden;
}
#liBox {
width: 200px;height: 20px;
position: absolute;
text-align: center;
top: -40px;color: coral;
transition: all 1s ease-in-out;
}
#box:hover #liBox {
top: 100px;
}
</style>
<body>
<div id="box">
<div id="liBox">
<p>因为热爱<br>所以一往无前</p>
</div>
</div>
</body>
</html>