教你用HTML+CSS实现百叶窗动画效果
warning:
这篇文章距离上次修改已过187天,其中的内容可能已经有所变动。
以下是一个简单的HTML和CSS代码示例,用于实现百叶窗动画效果:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>百叶窗动画</title>
<style>
.blind {
width: 200px;
height: 150px;
background-color: #f0f0f0;
position: relative;
margin: 50px;
}
.blind::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 50%;
background-color: white;
transition: all 0.5s ease;
}
.blind:hover::before {
top: 50%;
}
</style>
</head>
<body>
<div class="blind"></div>
</body>
</html>
这段代码创建了一个.blind
类,它在鼠标悬停时显示出百叶窗动画效果。.blind::before
伪元素用于创建百叶窗的上半部分,并且通过CSS的transition
属性实现平滑的动画效果。当鼠标悬停在.blind
元素上时,::before
伪元素的top
属性从0
变为50%
,从而实现百叶窗从上到下关闭的效果。
评论已关闭