Sun, Earth and CSS3
Hãy cùng tạo ra một Hệ mặt trời tuyệt đẹp với Trái đất, Mặt trời, Mặt trăng... bằng CSS3CSS
html, body {
/* The universe takes up all available space */
width: 100%;
height: 100%;
overflow: hidden;
/* The universe is black */
background-image: url('http://www.truthinsideofyou.org/wp-content/uploads/2015/01/Space.tga_.jpg');
}
#sun {
position: absolute;
/* Positions the top-left corner of the image to be *
/* in the middle of the box */
border-color: orange;
border-width: 2px;
border-style: solid;
border-radius: 90%;
box-shadow: 0 0 140px orange;
top: 50%;
left: 50%;
/* Play with these numbers to see what it does */
height: 200px;
width: 200px;
margin-top: -100px;
margin-left: -100px;
-webkit-animation: blink 3.0s linear infinite;
-moz-animation: blink 3.0s linear infinite;
-ms-animation: blink 3.0s linear infinite;
-o-animation: blink 3.0s linear infinite;
animation: blink 3.0s linear infinite;
}
#earth {
/* Style your earth */
border-color: none;
border-width: 1px;
border-style: solid;
border-radius: 50%;
box-shadow: 0 0 64px black;
position: absolute;
top: 0;
left: 50%;
height: 50px;
width: 50px;
margin-left: -25px;
margin-top: -25px;
-webkit-animation: spin-right 5s linear infinite;
-moz-animation: spin-right 5s linear infinite;
-ms-animation: spin-right 5s linear infinite;
-o-animation: spin-right 5s linear infinite;
animation: spin-right 5s linear infinite;
}
#earth-orbit {
/* For Section #2 */
position: absolute;
top: 50%;
left: 50%;
width: 700px;
height: 700px;
margin-top: -350px;
margin-left: -350px;
border-width: 1px;
border-style: dotted;
border-color: black;
border-radius: 50%;
-webkit-animation: spin-right 10s linear infinite;
-moz-animation: spin-right 10s linear infinite;
-ms-animation: spin-right 10s linear infinite;
-o-animation: spin-right 10s linear infinite;
animation: spin-right 10s linear infinite;
}
#moon {
/* Style your earth */
border-color: none;
border-width: 1px;
border-style: solid;
border-radius: 50%;
box-shadow: 0 0 64px black;
position: absolute;
top: 0;
left: 50%;
height: 10px;
width: 10px;
margin-left: -25px;
margin-top: -25px;
-webkit-animation: spin-left 5s linear infinite;
-moz-animation: spin-left 5s linear infinite;
-ms-animation: spin-left 5s linear infinite;
-o-animation: spin-left 5s linear infinite;
animation: spin-left 5s linear infinite;
}
#moon-orbit {
/* For Section #2 */
position: absolute;
top: 0;
left: 50%;
height: 60px;
width: 60px;
margin-left: -25px;
margin-top: -25px;
border-width: 0px;
border-style: dotted;
border-color: white;
border-radius: 50%;
-webkit-animation: spin-left 1s linear infinite;
-moz-animation: spin-left 1s linear infinite;
-ms-animation: spin-left 1s linear infinite;
-o-animation: spin-left 1s linear infinite;
animation: spin-left 1s linear infinite;
}
#mercury {
/* Style your earth */
border-color: none;
border-width: 0px;
border-style: solid;
border-radius: 50%;
box-shadow: 0 0 64px black;
position: absolute;
top: 0;
left: 50%;
height: 25px;
width: 25px;
margin-left: -25px;
margin-top: -25px;
-webkit-animation: spin-right 2s linear infinite;
-moz-animation: spin-right 2s linear infinite;
-ms-animation: spin-right 2s linear infinite;
-o-animation: spin-right 2s linear infinite;
animation: spin-right 5s linear infinite;
}
#mercury-orbit {
/* Style your earth */
position: absolute;
top: 50%;
left: 50%;
width: 300px;
height: 300px;
margin-top: -150px;
margin-left: -150px;
border-width: 0px;
border-style: dotted;
border-color: black;
border-radius: 50%;
-webkit-animation: spin-right 4s linear infinite;
-moz-animation: spin-right 4s linear infinite;
-ms-animation: spin-right 4s linear infinite;
-o-animation: spin-right 4s linear infinite;
animation: spin-right 4s linear infinite;
}
#venus {
/* Style your earth */
border-color: none;
border-width: 0px;
border-style: solid;
border-radius: 50%;
box-shadow: 0 0 64px black;
position: absolute;
top: 0;
left: 50%;
height: 37px;
width: 37px;
margin-left: -25px;
margin-top: -25px;
-webkit-animation: spin-right 8s linear infinite;
-moz-animation: spin-right 8s linear infinite;
-ms-animation: spin-right 8s linear infinite;
-o-animation: spin-right 8s linear infinite;
animation: spin-right 8s linear infinite;
}
#venus-orbit {
/* Style your earth */
position: absolute;
top: 50%;
left: 50%;
width: 500px;
height: 500px;
margin-top: -250px;
margin-left: -250px;
border-width: 0px;
border-style: dotted;
border-color: black;
border-radius: 50%;
-webkit-animation: spin-right 6s linear infinite;
-moz-animation: spin-right 6s linear infinite;
-ms-animation: spin-right 6s linear infinite;
-o-animation: spin-right 6s linear infinite;
animation: spin-right 6s linear infinite;
}
@-webkit-keyframes spin-right {
100% {
-webkit-transform: rotateZ(360deg);
-moz-transform: rotateZ(360deg);
-ms-transform: rotateZ(360deg);
-o-transform: rotateZ(360deg);
transform: rotateZ(360deg);
}
}
@keyframes spin-right {
100% {
-webkit-transform: rotateZ(360deg);
-moz-transform: rotateZ(360deg);
-ms-transform: rotateZ(360deg);
-o-transform: rotateZ(360deg);
transform: rotateZ(360deg);
}
}
@-webkit-keyframes spin-left {
100% {
-webkit-transform: rotateZ(-360deg);
-moz-transform: rotateZ(-360deg);
-ms-transform: rotateZ(-360deg);
-o-transform: rotateZ(-360deg);
transform: rotateZ(-360deg);
}
}
@keyframes spin-left {
100% {
-webkit-transform: rotateZ(-360deg);
-moz-transform: rotateZ(-360deg);
-ms-transform: rotateZ(-360deg);
-o-transform: rotateZ(-360deg);
transform: rotateZ(-360deg);
}
}
@keyframes blink {
0% { box-shadow: 0px 0px 180px 2px orange; }
50% { box-shadow: 0px 0px 60px 2px orange; }
100% { box-shadow: 0px 0px 180px 2px orange; }
}
@-webkit-keyframes blink {
0% { box-shadow: 0px 0px 180px 2px orange; }
50% { box-shadow: 0px 0px 60px 2px orange; }
100% { box-shadow: 0px 0px 180px 2px orange; }
}
HTML
<html>
<head>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- Right below is an image of the sun -->
<img id="sun" src="http://www.jaiom18.com/wp-content/uploads/2011/05/Sun-500x500.jpg">
<!-- Insert the 'earth' on the next line -->
<div id="earth-orbit">
<div id="moon-orbit">
<img id="moon" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRvk9eCx6EtNi-I6qiRF_Km1MWFPFFGN8OTVriPTNI4jhiiToHEgw">
</div>
<img id="earth" src="http://www.jeremyperson.com/wp-content/uploads/2009/06/earth-500x500.jpg">
</div>
<div id="mercury-orbit">
<img id="mercury" src="http://www.planetsforkids.org/images/planets/mercury.jpeg">
</div>
<div id="venus-orbit">
<img id="venus" src="http://www.myinterestingfacts.com/wp-content/uploads/2013/10/Mercury-Planet.jpg">
</div>
</body>
</html>
Nếu có bất kỳ vấn đề khó khăn hay câu hỏi gì, bạn đừng ngần ngại, hãy để lại bình luận ở form bên dưới nhé.
Chúc bạn thành công!
Mẹo nhỏ khi bình luận