Page #6 - Neography


Our Solar Sys­tem in CSS3.

Tuesday, May 18th, 2010

This is an attempt to recre­ate our solar sys­tem using CSS3 fea­tures such as border-radius, trans­forms and anim­a­tions. The res­ult is sur­pris­ing and quite interesting.

These past few months I’ve been explor­ing CSS3, try­ing to learn some of it’s new fea­tures and get­ting a feel for which browsers sup­port it. A few weeks back I put out my first exper­i­ment explor­ing @font-face and trans­forms. This time, I set out to exper­i­ment with border-radius, and what I thought was going to be a bor­ing little pro­ject turned out to be quite interesting.

Our Solar Sys­tem in Mod­ern Browsers

Our Solar System

Take a look for your­self, using only CSS and HTML I man­aged to cre­ate a small sim­u­la­tion of our solar system.

For a bet­ter exper­i­ence please view it on Safari, under chrome the anim­a­tions lag for some reason.

The Details

Orbits and plan­ets are all cre­ated using border-radius, while the anim­a­tion is done via –web­kit anim­a­tion prop­er­ties and trans­form. Below are examples of the code used.

border-radius

ul.solarsystem li.sun {
    width: 40px;
    height: 40px;
    -webkit-border-radius: 20px;
    -moz-border-radius: 20px;
    border-radius: 20px;
}

Anim­a­tions & Transforms

ul.solarsystem li {
    -webkit-animation-iteration-count:infinite;
    -webkit-animation-timing-function:linear;
    -webkit-animation-name:orbit;
}
ul.solarsystem li.earth span {
    -webkit-animation-iteration-count:infinite;
    -webkit-animation-timing-function:linear;
    -webkit-animation-name:moon;
}
ul.solarsystem li.mercury {-webkit-animation-duration:5s;}
ul.solarsystem li.venus {-webkit-animation-duration:8s;}
ul.solarsystem li.earth {-webkit-animation-duration:12s;}
ul.solarsystem li.earth span {-webkit-animation-duration:2s;}
ul.solarsystem li.mars {-webkit-animation-duration:20s;}
ul.solarsystem li.asteroids_meteorids {-webkit-animation-duration:50s;}
ul.solarsystem li.jupiter {-webkit-animation-duration:30s;}
ul.solarsystem li.saturn {-webkit-animation-duration:60s;}
ul.solarsystem li.uranus {-webkit-animation-duration:70s;}
ul.solarsystem li.neptune {-webkit-animation-duration:100s;}
ul.solarsystem li.pluto {-webkit-animation-duration:120s;}

@-webkit-keyframes orbit { 
from { -webkit-transform:rotate(0deg) } 
to { -webkit-transform:rotate(360deg) } }

Anim­a­tions and trans­itions will only work on –web­kit browsers, other mod­ern browsers will dis­play a static ver­sion of the solar sys­tem rendered using border-radius, with the excep­tion of IE of course.

Inter­net Explorer’s Par­al­lel Flat Universe:

Our Solar System in IE

Yep, in the eyes of Inter­net Explorer our uni­verse is flat and boring.

So there you have it, I think it’s pretty impress­ive what we can accom­plish with a few lines of CSS these days.

Oh, and yes… I kept Pluto ;-)

68 Comments

  1. 1
    jacy May 18th, 2010

    Super cool! Only, Pluto isn’t a planet anymore…

  2. 2
    Alex Giron May 18th, 2010

    @Jacy, yeah I knew that but decided to leave it in… I call this our Old School Solar System :-)

  3. 3
    Andrew Cornett May 18th, 2010

    Inter­net Explorer, the browser for squares.

  4. 4
    Andy Hume May 18th, 2010

    Great stuff…

    Can you make it to Sci­ence Hackday? :)

    http://blog.andyhume.net/solar-system-model-in-css
    http://sciencehackday.com/

  5. 5
    Andrew Dupont May 18th, 2010

    The anim­a­tions lag in Chrome because only Safari (on Snow Leo­pard) and MobileSa­fari (on recent ver­sions of iPhone OS) do hardware-acceleration of –webkit-transform anim­a­tions. Here’s more than you ever wanted to know about this.

  6. 6
    Kurt Cruse May 18th, 2010

    Very well executed. Great stuff.

  7. 7
    Tito Ciuro May 18th, 2010

    Excel­lent! One issue though: when you view the solar sys­tem page on an iPad in land­scape mode, the “On Twit­ter” and “About this Exper­i­ment” but­tons get drawn in the middle of the document.

  8. 8
    Alex Giron May 18th, 2010

    @Andy Hah! Awe­some, small world…

    @Andrew I see, thanks for the info.

    @Tito I’ll look into it, thanks!

  9. 9
    Eric May 18th, 2010

    Except for the anim­a­tion and Jupiter, it looks fine on Inter­net Explorer 9.

  10. 10
    Eric May 18th, 2010

    Sat­urn, damn it.

  11. 11
    Gabri May 18th, 2010

    very nice , I like the moon so much Great job

  12. 12
    Scott May 18th, 2010

    Um… this is quite superb.

  13. 13
    Scott L May 18th, 2010

    Look­ing good Alex.

    Andrew D– right, funny how it anim­ates smooth as but­ter on my iphone but stut­ters on my core i7 machine in Chrome. Hope Chrome 6 has D2D accel­er­a­tion out of the box!

  14. 14
    Jon Osmond May 18th, 2010

    This is truly awe­some. Love it.

  15. 15
    David Trang May 18th, 2010

    Man, you gotta love IE some­times just for the humor. Kind of like that annoy­ing kid brother that’s always linger­ing around.

  16. 16
    Syed Balkhi May 18th, 2010

    This is another great example of CSS in mod­ern browsers. It was just yes­ter­day that I saw the CSS icons like iphone / heart made with CSS.

  17. 17
    Wes Peery May 18th, 2010

    Hey.. This is pretty cool stuff. Nice way to dis­play css3!

  18. 18
    andi May 19th, 2010

    awe­some!! =)

  19. 19
    Tetsuo May 19th, 2010

    This is really inspir­ing stuff. Con­grat­u­la­tions, Alex :)

  20. 20
    Webstandard-Blog May 19th, 2010

    Awe­some! You can really do a lot of things with anim­a­tion and roun­ded corners. Try out that boun­cing nav­ig­a­tion (without javascript)!

  21. 21
    Floatr May 19th, 2010

    Really great job, grats
    How­ever, the anim­a­tion simply eats up my CPU. Dont kill me :) but still flash would be more optimal from this point of view.

  22. 22
    Ulf May 19th, 2010

    Very well done, con­grats. Our uni­verse really looks a little weird on the IE ;-). Amaz­ing to see what’s pos­sible with CSS3.

  23. 23
    datenkind May 19th, 2010

    What a gor­geous Web­kit example. Really great stuff!

  24. 24
    xeonwell May 19th, 2010

    awe­some…

  25. 25
    Aditya Dipankar May 19th, 2010

    Pluto’s inclu­sion is jus­ti­fied. Like the say­ing goes: My Very Eleg­ant Mother Just Showed Us Nine Plan­ets! :P
    Great work!

  26. 26
    Peter May 19th, 2010

    The world doesn’t move that fast. It takes 24 Hours for the Earth to orbit the Sun.

    I’m actu­ally offen­ded to see this on my screen.

  27. 27
    Stijn May 19th, 2010

    “Earth orbit Sin in 24 hours.” Oh Peter, you’re such a tool. ;) As for the anim­a­tion: kudos!

  28. 28
    Simone May 19th, 2010

    Many con­grats.
    “Yep, in the eyes of Inter­net Explorer our uni­verse is flat and bor­ing”: this is the most appro­pri­ate metaphora.

  29. 29
    Daniel Wood May 19th, 2010

    @Peter assum­ing you were being ser­i­ous, you should prob­ably seek addi­tional school­ing — the Earth orbits the Sun once a year, roughly every 365 days.

    @Alex excel­lent job, very impressive!

  30. 30
    Kashter May 19th, 2010

    excel­lent idea, great work! respect

  31. 31
    Chokladkakan May 19th, 2010

    People are bor­ing. Pluto is too a planet: a dwarf planet. It has more moons than your pre­cious Earth, pessimists.

    Any­way: fant­astic work!

  32. 32
    Lars May 19th, 2010

    Great exper­i­ment. And I like the IE metaphor :)

  33. 33
    Michael May 19th, 2010

    Great stuff. Very nicely done!

  34. 34
    Max May 19th, 2010

    This is like SO COOL!

  35. 35
    Guido Tapia May 19th, 2010

    Whilst I think that using CSS to do com­plex anim­a­tions is stretch­ing the friend­ship a little bit, I must say that that is pretty cool!! Great work

  36. 36
    Beben May 19th, 2010

    so interest develop of CSS code
    so grow up to fast
    thanks

  37. 37
    Deluxe Blog Tips May 20th, 2010

    Great! The effect is really cool and impress­ive. Nice work :)

  38. 38
    S May 20th, 2010

    Que bonito.
    Gracias

  39. 39
    Chris May 20th, 2010

    Damn impress­ive work…thanks for shar­ing this. And I also love your com­ment area formatting!!!

  40. 40
    Tony Stewart (RockIsSponge) May 20th, 2010

    Have to admit — there’s some­thing a bit design-sexy about IE’s inter­pret­a­tion! Retro and bit­mapped almost.

  41. 41
    andrew May 20th, 2010

    @Floatr the anim­a­tion runs about 8 — 10% CPU on my 13″ Mac­book Pro, whereas Flash would be some­where like 50 — 100%.

  42. 42
    Nico Gubler May 21st, 2010

    impressiv exper­i­ment. Thank you for sharing

  43. 43
    Shaun_R May 21st, 2010

    Very cool, but not tech­nic­ally accur­ate. The moon orbits Earth more than 6 times in an orbit of the Sun… Sorry :(

    Oh, and not all orbits are dead circles… Plus, I think Jupiter should be a little big­ger than the rest of them :P hahaha.

    In any case, abso­lutely totally awe­some!! Well done!!

  44. 44
    Jeff Dickey May 21st, 2010

    Once again, shouldn’t the early ver­sions of Microsoft’s browser (up to 7 or so) be more accur­ately termed “Inter­net Exploder?” “Par­al­lel flat uni­verse” indeed!

  45. 45
    Urs May 24th, 2010

    i really like this one! very nice inspir­a­tion, dude. thanks for sharing.

  46. 46
    Elijah May 24th, 2010

    Very great! really cool

  47. 47
    Greg Babula May 24th, 2010

    That’s amaz­ing, great work

  48. 48
    Josh May 24th, 2010

    Freakin Bril­liant, Thanks for sharing

  49. 49
    jive May 24th, 2010

    Good job, although Pluto’s orbit is not per­fectly circular.

  50. 50
    Jens Kilgenstein May 24th, 2010

    Yeah, push Your Web Design Into The Future With CSS3!

  51. 51
    j4k3 May 24th, 2010

    Inac­cur­ate but awe­some. I espe­cially like the shadow of earth cast on the moon.

  52. 52
    Alex Giron May 24th, 2010

    @everyone Thanks for the com­ments. I had lot of fun put­ting it together.

    The sim­u­la­tion was never meant to be a 100% accur­ate, rather more like an info-graphic.

  53. 53
    khan May 25th, 2010

    Nice Work, Great!

  54. 54
    sbuster May 25th, 2010

    Per­fect, is very work

  55. 55
    Lulu May 25th, 2010

    Typekit really needs to resolve FF dis­play issues, oth­er­wise this is a great experiment.

  56. 56
    Ricardo Zea May 25th, 2010
  57. 57
    Scott Prock May 25th, 2010

    I’m amazed at what can be done with CSS these days. I’m an old school tables guy who kicked a screamed at the thought of con­vert­ing to CSS … after using it for nearly a year, I wish I had con­ver­ted sooner ;-)

    Excel­lent use of the new stand­ards, thank you for cre­at­ing it.

    … Scott

  58. 58
    Scott Prock May 25th, 2010

    … oh, and I for­got to com­ment on the com­ment­ing structure …

    I love the way it runs hori­zontal, dif­fer­ent, and unique.

    … Scott

  59. 59
    Amol Bhokare May 25th, 2010

    awe­some…!!!

  60. 60
    Srinivas Tamada May 26th, 2010

    Excel­lent Work..

  61. 61
    Laurence May 26th, 2010

    Good test of Chrome — on my MBP with Chrome CPU usage for i core goes to 98% (in Safari it’s ~6%). We have a way to go until HTML 5/CSS 3 is the answer.

  62. 62
    Leon May 26th, 2010

    It’s awe­some, I love it, only one bit of con­struct­ive cri­ti­cism would be more accur­ate orbits, but I don’t know how feas­ible this would be with the cur­rent HTML5/CSS3, or how many hours it would take (prob­ably too many for a simple tech demo) It’s bril­liant though, and shows how use­less flash is in the long term.

  63. 63
    Charles May 26th, 2010

    Next, Halley’s comet?

  64. 64
    Jessica May 26th, 2010

    I love this! It’s excit­ing to see glimpses into the future of the web. Thank you so much for put­ting this together!

  65. 65
    John May 26th, 2010

    Very nice! My 4-year-old won’t appre­ci­ate the eleg­ance of your code, but he’ll love this non­ethe­less. (Though he’ll also be quick to point out the prob­lem with Pluto’s orbit.)

    I do see the CPU spike oth­ers have poin­ted out (using Chrome on XP). No doubt this is being addressed in some stage of development.

    Also agree that this format for view­ing com­ments is wonderful!

    Regards,
    John Doyle

  66. 66
    May 26th, 2010

    Impress­ive !

  67. 67
    Colonel Kernel May 26th, 2010

    As a CSS3 exer­cise this is fant­astic, but, as I’m sure you’re aware, Flash was doing this more than a dec­ade ago. As I’m also sure you’re aware, this is sci­en­tific­ally com­ical and can not be rec­ti­fied using any amount of CSS. For an example of Flash’s power, check out http://j.mp/cxMpGq.

    Also, your com­ment dis­play is obnox­ious and a prime example of over design get­ting in the way of usability.

  68. 68
    Alex Giron May 26th, 2010

    @everyone, again thanks for the awe­some comments.

    For those say­ing the exper­i­ment isn’t sci­en­tific­ally accur­ate, well it wasn’t meant to be, it’s purely an exer­cise about CSS3 capabilities.

    Clos­ing com­ments on this one… Till next time!