只用css+html实现地球绕太阳旋转,月亮绕地旋转

这是一个使用HTML、CSS和JavaScript创建的太阳系模拟动画,展示了太阳、地球和月亮的运动轨迹。动画中,地球带有月球,并且两者都围绕太阳进行旋转。通过这段代码,可以了解网页动画的基本实现原理。
摘要由CSDN通过智能技术生成

<style>

    body{

      width: 100%;

      height: 100vh;

      margin: 0;

      padding: 0;

      box-sizing: border-box;

      display: flex;

      justify-content: center;

      align-items: center;

      background-color: black;

    }

    .container{

      width: 100%;

      height: 100%;

      display: flex;

      justify-content: center;

      align-items: center;

      position: relative;

    }

    .sun{

      position: absolute;

      width: 200px;

      height: 200px;

      background-color: yellow;

      border-radius: 50%;

      box-shadow: 0 0 5rem #fff, 0 0 5rem #fff;

    }

    .earth{

      position: absolute;

      width: 500px;

      height: 500px;

      /* background-color: aqua; */

      border-radius: 50%;

      border-style: solid solid none none;

      border-color: silver transparent transparent transparent;

      border-width: 0.1rem;

      animation: move 36.5s linear infinite;

    }

    .earth::before{

      content: '';

      width: 50px;

      height: 50px;

      background-color: blue;

      position: absolute;

      top: 50px;

      right: 50px;

      border-radius: 50%;

    }

    .moon{

      position: absolute;

      width: 120px;

      height: 120px;

      top: 12px;

      right: 12px;

      /* background-color: aqua; */

      border-radius: 50%;

      border-style: solid solid none none;

      border-color: silver transparent transparent transparent;

      border-width: 0.1rem;

      animation: move 24s linear infinite;

    }

    .moon::before{

      content: '';

      width: 30px;

      height: 30px;

      background-color: rgb(48, 48, 51);

      position: absolute;

      top: 0px;

      right: 0px;

      border-radius: 50%;

    }

    @keyframes move{

      to{

        transform: rotate(360deg);

      }

    }

  </style>

</head>

<body>

  <div class="container">

    <div class="sun"></div>

    <div class="earth">

      <div class="moon"></div>

    </div>

  </div>

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值