Skip to main content

Make an Interesting Animation using Pure CSS and HTML | Animation in CSS





 In this project, we will only use HTML and CSS to make an animation where the moon is rotating our earth.

HTML file

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>moon rotation around earth</title>

    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <article class="earth-demo">
        <div class="earth">
          <img src="https://cssanimation.rocks/images/random/earth.png" alt=""></div>

        <div class="moon-container">
          <div class="moon">
            <img src="https://cssanimation.rocks/images/random/moon.png" alt=""> </div>
        </div>
      </article>
</body>
</html>



CSS file

body{
    background-color: black;
    }
    .earth {
        position: absolute;
          top: calc(50% - 100px);
          left: calc(50% - 100px);
      }
      .earth img {
        height: 200px;
        position: absolute;
          top: 0;
          left: 0;
        width: 200px;
      }
      .moon-container {
        position: absolute;
          top: calc(50% - 25px);
          left: calc(50% - 25px);
      }
      .moon {
        animation: spin 20s linear infinite;
        background: none;
        height: 50px;
        pointer-events: none;
        transform-origin: 25px;
        width: 50px;
      }
      .moon img {
        height: 50px;
        transform: translateX(-160px) translateY(-160px);
        width: 50px;
      }
      .earth img, .moon img {
        border-radius: 50%;
        box-shadow: 0 0 12em 1em rgba(110, 140, 200, .6);
      }
      .earth img, .moon img {
        border-radius: 50%;
        box-shadow: 0 0 12em 1em rgba(110, 140, 200, .6);
      }
      @keyframes spin {
        to {
          transform: rotateZ(360deg);
        }
      }


Follow my socials:

Youtube:https://www.youtube.com/channel/UCU1qNFntn7dCi9uqyvrGKOg

Instagram: https://www.instagram.com/python.math/

Twitter:https://twitter.com/Pritish369


For any question or coding discussion, you can join my discord or telegram:

Discord:https://discord.gg/be7MmSuV

Telegram:https://t.me/Python_Math_Community


Comments