HTML实现九大行星,各个行星都能围绕太阳按照各自的轨道进行旋转;3. 图中有个别行星也有自己的小行星,该小行星也可以围绕它进行旋转;2. 要求各个轨道的旋转速度不一样;
时间: 2024-03-10 10:49:37 浏览: 16
好的,以下是一个可以实现您要求的HTML和CSS代码示例:
HTML代码:
```html
<div class="container">
<div class="sun"></div>
<div class="mercury orbit">
<div class="mercury-moon orbit"></div>
</div>
<div class="venus orbit">
<div class="venus-moon orbit"></div>
</div>
<div class="earth orbit">
<div class="earth-moon orbit"></div>
</div>
<div class="mars orbit">
<div class="mars-moon orbit"></div>
</div>
<div class="jupiter orbit">
<div class="jupiter-moon orbit"></div>
</div>
<div class="saturn orbit">
<div class="saturn-moon orbit"></div>
</div>
<div class="uranus orbit">
<div class="uranus-moon orbit"></div>
</div>
<div class="neptune orbit">
<div class="neptune-moon orbit"></div>
</div>
</div>
```
CSS代码:
```css
.container {
position: relative;
width: 600px;
height: 600px;
margin: 0 auto;
}
.sun {
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
width: 100px;
height: 100px;
border-radius: 50%;
background-color: #FFCE00;
animation: spin 10s linear infinite;
z-index: 10;
}
.orbit {
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
border-radius: 50%;
border: 1px dashed #aaa;
transform-origin: center center;
animation: orbit linear infinite;
}
.mercury {
width: 30px;
height: 30px;
margin-left: -15px;
animation-duration: 4s;
animation-delay: 0.5s;
}
.mercury-moon {
width: 10px;
height: 10px;
margin-left: -5px;
animation-duration: 2s;
animation-delay: 1s;
}
.venus {
width: 50px;
height: 50px;
margin-left: -25px;
animation-duration: 6s;
animation-delay: 1s;
}
.venus-moon {
width: 20px;
height: 20px;
margin-left: -10px;
animation-duration: 3s;
animation-delay: 1.5s;
}
.earth {
width: 70px;
height: 70px;
margin-left: -35px;
animation-duration: 8s;
animation-delay: 1.5s;
}
.earth-moon {
width: 30px;
height: 30px;
margin-left: -15px;
animation-duration: 4s;
animation-delay: 2s;
}
.mars {
width: 90px;
height: 90px;
margin-left: -45px;
animation-duration: 10s;
animation-delay: 2s;
}
.mars-moon {
width: 40px;
height: 40px;
margin-left: -20px;
animation-duration: 5s;
animation-delay: 2.5s;
}
.jupiter {
width: 140px;
height: 140px;
margin-left: -70px;
animation-duration: 14s;
animation-delay: 3s;
}
.jupiter-moon {
width: 50px;
height: 50px;
margin-left: -25px;
animation-duration: 7s;
animation-delay: 3.5s;
}
.saturn {
width: 180px;
height: 180px;
margin-left: -90px;
animation-duration: 18s;
animation-delay: 3.5s;
}
.saturn-moon {
width: 70px;
height: 70px;
margin-left: -35px;
animation-duration: 9s;
animation-delay: 4s;
}
.uranus {
width: 210px;
height: 210px;
margin-left: -105px;
animation-duration: 22s;
animation-delay: 4s;
}
.uranus-moon {
width: 90px;
height: 90px;
margin-left: -45px;
animation-duration: 11s;
animation-delay: 4.5s;
}
.neptune {
width: 240px;
height: 240px;
margin-left: -120px;
animation-duration: 26s;
animation-delay: 4.5s;
}
.neptune-moon {
width: 110px;
height: 110px;
margin-left: -55px;
animation-duration: 13s;
animation-delay: 5s;
}
@keyframes orbit {
from {
transform: rotate(0deg) translateX(150px) rotate(0deg);
}
to {
transform: rotate(360deg) translateX(150px) rotate(-360deg);
}
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
```
以上代码将会在一个 600px x 600px 的容器内展示太阳系中的九大行星,每个行星都有自己的轨道和大小,并且都会沿着其轨道以不同的速度运动。某些行星(如地球)还有自己的卫星,而这些卫星也会围绕其父行星进行旋转。请注意,上面的CSS代码中的动画效果仅适用于最新版本的现代浏览器,而在旧版浏览器中可能会有兼容性问题。