<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS3 日食场景</title>
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(to bottom, #1a1a2e, #16213e, #0f3460);
overflow: hidden;
font-family: Arial, sans-serif;
}
.scene {
position: relative;
width: 100%;
height: 100%;
}
.sun {
position: absolute;
width: 150px;
height: 150px;
background: radial-gradient(circle, #ffde59, #ff8c00);
border-radius: 50%;
box-shadow: 0 0 50px #ff8c00, 0 0 100px #ff8c00;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1;
}
.moon {
position: absolute;
width: 160px;
height: 160px;
background: #16213e;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
animation: eclipse 10s linear infinite;
}
@keyframes eclipse {
0% {
transform: translate(-250%, -50%);
}
40% {
transform: translate(-50%, -50%);
}
60% {
transform: translate(-50%, -50%);
}
100% {
transform: translate(150%, -50%);
}
}
.corona {
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 0;
background: radial-gradient(circle, rgba(255,140,0,0.8) 0%, rgba(255,140,0,0) 70%);
opacity: 0;
animation: corona 10s linear infinite;
}
@keyframes corona {
35% { opacity: 0; }
45% { opacity: 1; }
55% { opacity: 1; }
65% { opacity: 0; }
}
.stars {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
}
.star {
position: absolute;
background-color: white;
border-radius: 50%;
animation: twinkle 2s infinite alternate;
}
@keyframes twinkle {
from { opacity: 0.2; }
to { opacity: 1; }
}
.footer {
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
color: white;
font-size: 14px;
z-index: 10;
}
.footer a {
color: #ff8c00;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="scene">
<div class="stars" id="stars"></div>
<div class="sun"></div>
<div class="moon"></div>
<div class="corona"></div>
<div class="footer">
</div>
</div>
<script>
// 创建星星
const starsContainer = document.getElementById('stars');
const starsCount = 200;
for (let i = 0; i < starsCount; i++) {
const star = document.createElement('div');
star.classList.add('star');
// 随机大小 (1-3px)
const size = Math.random() * 2 + 1;
star.style.width = `${size}px`;
star.style.height = `${size}px`;
// 随机位置
star.style.left = `${Math.random() * 100}%`;
star.style.top = `${Math.random() * 100}%`;
// 随机闪烁延迟
star.style.animationDelay = `${Math.random() * 2}s`;
starsContainer.appendChild(star);
}
</script>
</body>
</html>