HTML5+CSS3小实例:纯CSS实现奥运五环
以下是使用纯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>
.ring {
width: 100px;
height: 100px;
border-radius: 50%;
position: absolute;
animation: rotate 5s linear infinite;
}
.ring:nth-child(1) {
background: #F58517;
left: 45px;
top: 45px;
animation-delay: -2.5s;
}
.ring:nth-child(2) {
background: #0268ae;
left: 45px;
top: 45px;
animation-delay: -2s;
}
.ring:nth-child(3) {
background: #e42228;
left: 45px;
top: 45px;
animation-delay: -1.5s;
}
.ring:nth-child(4) {
background: #06b315;
left: 45px;
top: 45px;
animation-delay: -1s;
}
.ring:nth-child(5) {
background: #1e90ff;
left: 45px;
top: 45px;
animation-delay: -0.5s;
}
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="ring"></div>
<div class="ring"></div>
<div class="ring"></div>
<div class="ring"></div>
<div class="ring"></div>
</body>
</html>
这段代码使用了CSS3的动画(@keyframes
)特性来实现旋转效果,并通过nth-child
选择器为每个圆环设置不同的颜色和动画延迟,从而模拟出五环旋转的效果。
评论已关闭