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);
}
}
Comments
Post a Comment