Moon? (Attempt #2) & Mars!


#1

I'm having trouble getting my moon to line up with my earth.
Here's the HTML:

<html>
    <head>
        <link rel="stylesheet" href="style.css" />
    </head>
    
    <body>
        <!-- Right below is an image of the sun -->
        <img id="sun" src="http://goo.gl/PmbqZa">
        
        <!-- Insert the 'earth' on the next line -->
        <div id='earth-orbit'>
            <img id ="earth" src="http://goo.gl/41IWnf">
            <div id ='moon-orbit'>
                <img id ="moon" src ="http://www.nasa.gov/sites/default/files/thumbnails/image/as11-44-6667.jpg">
            </div>
        </div>
        <div id='mars-orbit'>
            <img id ="mars" src ="http://mars.nasa.gov/images/Mars_globe_1584x1584_2.jpg">
        </div>
    </body>
</html>

And here's the CSS:

html, body {
    /* The universe takes up all available space */
    width: 100%;
    height: 100%;
    
    /* The universe is black */
    background-color: black;
}

#sun {
    position: absolute;
    /* Positions the top-left corner of the image to be *
    /* in the middle of the box */
    top: 50%;
    left: 50%;
    
    /* Play with these numbers to see what it does */
    height: 200px;
    width: 200px;
    margin-top: -100px; 
    margin-left: -100px;
    border-color: orange;
    border-width: 0px;
    border-style: solid;
    border-radius: 50%;
    box-shadow: 0 0 100px yellow;
}

#earth {
        position:absolute;
        top: 0;
        left: 50%;
        height: 50px;
        width: 50px;
        
        margin-left: -25px;
        margin-top: -25px;
        
        border-color: green;
        border-width:0px;
        border-style: solid;
        border-radius:50%;
}

#earth-orbit {
    position: absolute;
    top:50%;
    left:50%;
    width:500px;
    height: 500px;
    
    margin-top:-250px;
    margin-left: -250px;
    
    border-width:2px;
    border-style:dotted;
    border-color:white;
    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{
    position: absolute;
    top: 50%;
    left 50%;
    width: 25px;
    height: 25px;
    
    margin-left:-25px;
    margin-top:-25;
    
    border-width: 0px;
    border-style:solid;
    border-color:gray;
    border-radius: 50%;
}
#moon-orbit{
    position: absolute;
    top:35%;
    left:35%;
    width:250px;
    height: 250px;
    margin-top:-250px;
    margin-left:-250px;
    border-width: 2px;
    border-style: dotted;
    border-color: white;
    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;
}
#mars {
        position:absolute;
        top: 0;
        left: 50%;
        height: 50px;
        width: 50px;
        
        margin-left: -25px;
        margin-top: -25px;
        
        border-color: green;
        border-width:0px;
        border-style: solid;
        border-radius:50%;
}

#mars-orbit {
    position: absolute;
    top:25%;
    left:40%;
    width:750px;
    height: 750px;
    
    margin-top:-200px;
    margin-left: -250px;
    
    border-width:2px;
    border-style:dotted;
    border-color:white;
    border-radius:50%;
    
    -webkit-animation: spin-right 18.8219178082s linear infinite;
     -moz-animation: spin-right 18.8219178082s linear infinite;
      -ms-animation: spin-right 18.8219178082s linear infinite;
       -o-animation: spin-right 18.8219178082s linear infinite;
          animation: spin-right 18.8219178082s linear infinite;
}

@-webkit-keyframes spin-right {
  100% {
    -webkit-transform: rotate(360deg);
       -moz-transform: rotate(360deg);
        -ms-transform: rotate(360deg);
         -o-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}

@keyframes spin-right {
  100% {
    -webkit-transform: rotate(360deg);
       -moz-transform: rotate(360deg);
        -ms-transform: rotate(360deg);
         -o-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}

#2

Hi 1019538,

Sorry for the slow reply!

I'm not able to run your code and test it right now, but I'd suggest putting #earth inside #moon-orbit, then giving #moon-orbit relative positioning (position: relative;), and #earth absolute positioning (position: absolute;) and top: 50%; left: 50%; to (roughly) center it inside the moon's orbit.

Also, a look through posts from other people doing this may help you :slightly_smiling: