This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Sun, Earth, and Code Forum

View Course » View Exercise

543 points
D45c441d9ef37d8f015d1fa6fc29b42c?s=140&d=retro
Submitted by
catherine226714
almost 4 years ago

How can I increase/decrease the size of a planet's orbit?

My CSS code:

  /*Orbit speeds:
Mercury-2s
Venus-6s
Earth-10s       Moon-0.75s
Mars-19s
Jupiter-120s
Saturn-300s
Uranus-840s
Neptune-1650s
Pluto-2480s

Diameter (x/25px):
Mercury- 9.575px
Venus-23.725px
Earth-25px  Moon-6.81px
Mars-13.3px
Jupiter-280.25px
Saturn-236.25px
Uranus-100.25px
Neptune-97px
Pluto-4.675px

Distance from Sun(x/-100px):
*/
html {
    background-color: #000;
}

#sun {
    position: absolute;
    height: 100px;
    width: 100px;

    top: 50%;
    left: 50%;
    margin-left: -50px;
    margin-top: -50px;
}

#mercury {
    height: 9.575px;
    width: 9.575px;
}

#mercury-orbit {
   position: absolute; 
   height: 100px; 
   width: 100px;
   top: 50%;
   left: 50%;

   margin-left: -50px;
   margin-top: -50px;

   border-radius: 50%;
   border: 1px dotted gray;

   -webkit-animation: spin-right 2s linear infinite;
}

/*#venus {
    height: 23.725px;
    width: 23.725px;
}

#venus-orbit {
    position: absolute;
    height: 100px;
    width: 100px;
    top: 50%;
    left: 50%;

    margin-left: -50px;
    margin-top: -50px;

    border-radius: 50%;
    border: 1px dotted gray;

    -webkit-animation: spin-right 6s linear infinite;
}*/

#earth {
    height: 25px;
    width: 25px;
}

#earth-orbit {
    position: absolute;
    height: 200px;
    width: 200px;
    top: 50%;
    left: 50%;

    margin-left: -100px;
    margin-top: -100px;


    border-radius: 50%;
    border: 1px dotted gray;

    -webkit-animation: spin-right 10s linear infinite;
}

#moon {
    height: 6.81px;
    width: 6.81px;
}

#moon-orbit {
    top: 50%;
    left: 50%;

    height: 50px;
    width: 50px;

    margin-left: -12.5px;
    margin-bottom: -37px;

    border-radius: 50%;
   border: 1px dotted gray;

    -webkit-animation: spin-right 0.75s linear infinite;
}

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

This is unfinished; as you can see, I don't have all the planets included yet.

Let's say I want to move Earth a bit closer to the Sun. How would I do that?
(Note that the dotted borders are temporary and are included to show where the planets orbit.)
Thank you in advance for your time.


1 vote

permalink

You should change the size values of the earth-orbit, venus-orbit, etc

This values will set the size of the orbit

   height: 400px; 
   width: 400px;

and this values will set the "position"

margin-top: -200px;
margin-left: -200px;

Note: the margins should be the half of the size, in negative.
Ex: 300px size, -150 margin (both top and left)
Ex: 500px size, -250 margin (both top and left)

1049 points
52fa38789c4e9d47d3002adc_457600436
Submitted by
Deko
almost 4 years ago