This demo was created by Zachary Johnson, a Minneapolis, MN based web developer who has also authored a jQuery plugin for animated “3D” rotation.

I’d like to show an example of a visual effect that can be accomplished using the new -moz-transform CSS transformation property that is available in the Firefox 3.5 browser. I was very excited to see this feature added to Firefox because I knew it would allow me to produce a faux-3D isometric effect, also sometimes called 2.5D. I created a demo where HTML content is mapped onto the faces of a “3D” isometric cube:

View the Demo in Firefox 3.5

isocube

The -moz-transform property can take a list of CSS transform functions including rotate, scale, skew, and translate. Or, multiple transformations can be done simultaneously using a single 2D affine transformation matrix. Because all of the CSS transformation functions work in two dimensions, true 3D transformations with perspective projection cannot yet be accomplished. In this demo, I use the rotate and skew transformation functions in order to create the isometric effect.

First, I define a container div for the cube, and then a square div for the top, left, and right faces of the cube.

<div class="cube">
    <div class="face top">
    </div>
    <div class="face left">
    </div>
    <div class="face right">
    </div>
</div>
.cube {
    position: absolute;
}
 
.face {
    position: absolute;
    width: 200px;
    height: 200px;
}

Without getting too wrapped up in isometric projection math, we have to rotate and skew the cube faces in order to turn each square div into a parallelogram where the angles of the vertices are 60° or 120°. Here are what those transformations look like using the new -moz-transform CSS property:

.top {
    -moz-transform: rotate(-45deg) skew(15deg, 15deg);
}
 
.left {
    -moz-transform: rotate(15deg) skew(15deg, 15deg);
}
 
.right {
    -moz-transform: rotate(-15deg) skew(-15deg, -15deg);
}

Now all that is left to do is to use absolute positioning to connect each transformed div in order to form the faces of the isometric cube. You can use matrix math to do this, or you could just move the faces around until they line up and it looks right.

To add to the 3D effect, I’ve shaded the isometric cube by assigning different colors to the faces. I also gave the cube a shadow. You can see that the shadow is basically just a copy of the top face of the cube moved down to the bottom left, and then I gave the shadow div a black background color and set opacity: 0.5; in the CSS to make it filter over the page background.

Any HTML, such as the text and form buttons in this example, can be put inside the div for any face of the cube. It will be translated into the correct perspective. Christopher Blizzard gave me the idea to throw video onto one side of the cube using the new HTML5 video tag now supported in Firefox 3.5. As you can see, it works great.

Finally, by making a copy of the cube markup and using two more of the CSS transformation functions, I was able to create a second cube. I made the cube 50% as big using a scale(0.5) transformation, and I moved it into place by using translate(600px, 400px).

I hope you found this demo to be interesting and that it opened up your mind to some exciting possibilities that Firefox 3.5 CSS transformations bring to the web.

CSS transformations are also supported by Safari 3.1+ and Chrome using the -webkit-transform CSS property.

45 comments

Post a comment
  1. Dan wrote on June 15th, 2009 at 12:48 pm:

    I haven’t seen the transforms used like that before, very cool. I like how all of the text is selectable.

    Reply

  2. Zacharias wrote on June 15th, 2009 at 1:24 pm:

    Why does the text jiggle as I select it?

    Reply

  3. Magne Andersson wrote on June 15th, 2009 at 1:49 pm:

    I can’t see the text under the shadow of the big box, is the image in the article from an old version, or does it render differently on a Mac (which the button suggests it is)?

    Reply

  4. Michael Kozakewich wrote on June 15th, 2009 at 1:59 pm:

    Would jQuery be able to handle animations of that? I’ll have to check. If you could do some crazy stuff to spin out a cube to display an external website in an iframe, it would be fantabulous.

    You could have buttons on the side to control navigation.

    Reply

  5. Pino wrote on June 15th, 2009 at 2:42 pm:

    Lol, this example crashes my browser. Mozilla/5.0 (Windows; U; Windows NT 6.0; nl; rv:1.9.1) Gecko/20090612 Firefox/3.5. A very bad example of Firefox’s greatness :P

    Reply

  6. Pingback from Transformaciones 3D en Firefox 3.5 - Gregorio Espadas on June 15th, 2009 at 2:49 pm:

    [...] Mozilla Hacks. Share this on del.icio.usDigg this!Stumble upon something good? Share it on StumbleUponShare this [...]

    Reply

  7. Magne Andersson wrote on June 15th, 2009 at 5:19 pm:

    @Michael Kozakewich – Is this what you mean? http://www.zachstronaut.com/lab/3d.html http://www.zachstronaut.com/projects/rotate3di/

    Reply

  8. Rowno wrote on June 15th, 2009 at 6:42 pm:

    Lol, the demo crashes my Firefox too when I try to select text on the box.

    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b99) Gecko/20090605 Firefox/3.5b99 (.NET CLR 3.5.30729) on Windows XP

    Reply

  9. kbrosnan wrote on June 15th, 2009 at 7:41 pm:

    Would either of the people who had crashes type about:crashes in the address bar and check for a crash ID. Either post back to this blog or email me commenter name at gmail dot com

    http://support.mozilla.com/en-US/kb/Mozilla+Crash+Reporter#Viewing_crash_reports

    Reply

  10. g zgodero wrote on June 15th, 2009 at 8:17 pm:

    Nothing happens at all, no action, no crash… nada.

    Reply

  11. Pingback from Firefox 3.5 y las transformaciones 3D | aNieto2K on June 16th, 2009 at 12:01 am:

    [...] 3.5 nos delitará con la posibilidad de realizar tranformaciones 3D nativamente. Esta propiedad del CSS nos permitirá, entre otras cosas, dar efecto de profundidad a los [...]

    Reply

  12. Pingback from Firefox 3.5 y las transformaciones 3D : Blogografia on June 16th, 2009 at 12:40 am:

    [...] 3.5 nos delitará con la posibilidad de realizar tranformaciones 3D nativamente. Esta propiedad del CSS nos permitirá, entre otras cosas, dar efecto de profundidad a los [...]

    Reply

  13. Quezako wrote on June 16th, 2009 at 12:54 am:

    I had a crash 1st time I clicked on th video with Fx 3.5b99 but I must admit this demo is amazing!

    Reply

  14. tomh wrote on June 16th, 2009 at 3:25 am:

    Quite cool, certainly shows some over the top uses for the properties. I must say that I couldn’t help think of tags when seeing this… Lets hope people who are capable of using this tag know how to do so sensibly ;-)

    Reply

  15. Alfred Kayser wrote on June 16th, 2009 at 5:17 am:

    Great! Not just the video is transformed, but also the controlbar (when it is enabled)!

    Reply

  16. Pingback from Max Design - standards based web design, development and training » Some links for light reading (16/6/09) on June 16th, 2009 at 5:24 am:

    [...] 3D transforms in Firefox 3.5 – the isocube at hacks.mozilla.org [...]

    Reply

  17. web designer wrote on June 16th, 2009 at 4:30 pm:

    Thank you
    will try it
    I am just wondering how it will look like on ie7
    regards

    Reply

  18. Rowno wrote on June 16th, 2009 at 8:03 pm:

    The crash ID’s for both of my crashes on the isocube are 453109a7-8409-4c7a-aeda-176e72090615 and f50c518f-b86d-4e34-a890-491d92090615.

    Reply

  19. Pingback from 颠覆网络35天 ─ Firefox 3.5中的3D变形:isocube < MJiA on June 16th, 2009 at 10:25 pm:

    [...] 原文地址:3D transforms in Firefox 3.5 – the isocube 系列地址:颠覆网络35天 [...]

    Reply

  20. Quezako wrote on June 17th, 2009 at 1:40 am:

    66c35595-a93a-4934-bb20-4038a2090616

    Reply

  21. philoye wrote on June 17th, 2009 at 3:22 am:

    FYI, this demo works just find in Mac/Safari 4, well, at least, in a recent Webkit nightly build.

    Reply

  22. Magne Andersson wrote on June 17th, 2009 at 4:55 am:

    @Web designer: It won’t work in IE7, nor IE8. As we all know by now, Microsoft is slow and keeps new standards away from becoming popular.

    Reply

  23. Pingback from Mozilla Firefox 3.5 RC1b4 « Christoph Voigt on June 17th, 2009 at 2:38 pm:

    [...] noch sehr ruckelig – einen ersten Crash hatte ich bereits nach 5 Minuten beim testen der 3D-Transformierung. Generell findet man auf hacks.mozilla.org eine ganze Menge zum rumspielen, wenn man gerade mit der [...]

    Reply

  24. Pingback from the tristan washing machine at hacks.mozilla.org on June 17th, 2009 at 10:05 pm:

    [...] the video runs it uses the transformation property to rotate the video while it’s playing: function rotateMePlease() { // [...]

    Reply

  25. Pingback from Bryan Clark » Blog Archive » Cubed Mail on June 18th, 2009 at 4:59 pm:

    [...] in honor of the hacks.mozilla.org recent article called 3D transforms in Firefox 3.5 – the isocube I added a similar hack to my tabbed message example extension.  I give [...]

    Reply

  26. Pingback from Bryan Clark: Cubed Mail | Full-Linux.com on June 18th, 2009 at 11:06 pm:

    [...] in honor of the hacks.mozilla.org recent article called 3D transforms in Firefox 3.5 – the isocube I added a similar hack to my tabbed message example extension.  I give [...]

    Reply

  27. Denis Seleznev wrote on June 19th, 2009 at 9:31 am:

    I am a fan CSS transform! :)

    http://webfilin.ru/files/notes/text-photo/firefox/

    Reply

  28. Pingback from First look to Firefox 3.5 RC2 - Mozilla Links on June 19th, 2009 at 10:40 pm:

    [...] the specific device characteristics such as aspect ratio, resolution, color capabilities, and more; cool 3D and image/font effects thanks to the <canvas> element; and lots of [...]

    Reply

  29. Alexandre wrote on June 22nd, 2009 at 6:34 am:

    Crash everytime after a few seconds, with FF3.5 RC2 on Windows Vista 64-bit.

    Reply

  30. Alexandre wrote on June 22nd, 2009 at 7:36 am:

    kbrosnan: Sorry, no crash ID. It looks like Firefox dies before generating the report. It try to contact you by mail with more information.

    Reply

  31. Alexandre wrote on June 22nd, 2009 at 9:15 am:

    Videos of the crash in different formats (all can be read by VLC)
    http://alexandre.alapetite.fr/prive/temp/20090622-Firefox3.5rc2-crash-isocube-Vista64.avi
    http://alexandre.alapetite.fr/prive/temp/20090622-Firefox3.5rc2-crash-isocube-Vista64.mp4
    http://alexandre.alapetite.fr/prive/temp/20090622-Firefox3.5rc2-crash-isocube-Vista64.ogv

    Reply

  32. Quezako wrote on June 22nd, 2009 at 11:51 am:

    @Alexandre did you try to deactivate all your add-onds?
    I have no problem with Firefox 3.5 RC2 + Windows 7 x64.

    Reply

  33. Pingback from Monthly Interesting Links Roundup (June 2009) - 2 on June 26th, 2009 at 12:40 am:

    [...] CSS 3D transforms. Try the demo, and don’t forget to select some text on the page http://hacks.mozilla.org/2009/06/3d-transforms-isocube/ [...]

    Reply

  34. DarthNihilus wrote on June 29th, 2009 at 12:51 pm:

    Does not work correctly with FF 3.5 RC 3. Somehow they overlab eachothers font, i don’t know…

    Reply

  35. Pingback from Firefox 3.5 Released, Detailed Feature Review. | Taranfx: Technology Blog on June 30th, 2009 at 10:44 am:

    [...] are supported too, making it possible to rotate and skew page elements. This feature has been used experimentally to simulate isometric 3D rendering. In the following image, a playable video and selectable text [...]

    Reply

  36. Pingback from » Blog Archive » First look: Firefox 3.5 released, ready to “upgrade” the Web on July 1st, 2009 at 8:20 am:

    [...] are supported too, making it possible to rotate and skew page elements. This feature has been used experimentally to simulate isometric 3D rendering. In the following image, a playable video and selectable text [...]

    Reply

  37. SelenIT wrote on July 1st, 2009 at 11:04 am:

    Looks great! Thanks, Zachary and Christopher!

    But I’d like to suggest a little “improvement”: to replace the meaningless empty divs for the shadows of the cubes with other CSS3 (something like -moz-box-shadow: -398px 200px 3px rgba(0, 0, 0, 0.5); and the same with -webkit- for the top sides, this worked for me in Firefox 3.5, Safari 4/Win and Chrome 2).

    Reply

  38. Pingback from Upgrade to Firefox 3.5 on Ubuntu 9.04 – Jaunty Jackalope | gaarai.com on July 1st, 2009 at 5:26 pm:

    [...] 3-D cubes built with standard HTML content, including the new native video component. [...]

    Reply

  39. aroth wrote on July 3rd, 2009 at 4:47 pm:

    Add javascript to make the cube rotate in 3D, please.

    Reply

  40. Pingback from Everything Tech » Blog Archive » First look: Firefox 3.5 released, ready to “upgrade” the Web on July 5th, 2009 at 7:13 pm:

    [...] are supported too, making it possible to rotate and skew page elements. This feature has been used experimentally to simulate isometric 3D rendering. In the following image, a playable video and selectable text [...]

    Reply

  41. Andre wrote on July 15th, 2009 at 7:34 am:

    Are there w3c approved equivalents of these properties

    Reply

  42. Pingback from WebKit支持OS X 3D CSS变换 « 每日IT新闻,最新IT资讯,聚合多站点消息,保证你与世界同步 on July 16th, 2009 at 3:29 am:

    [...] 写道” Safari 4浏览器核心WebKit在最近的一次更新中加入了3D CSS变换支持,FireFox 3.5也支持该特性。3D [...]

    Reply

  43. Pingback from 谋智社区 » Blog Archives » 颠覆网络35天 ─ Firefox 3.5中的3D变形:isocube on July 23rd, 2009 at 8:33 pm:

    [...] 原文地址:3D transforms in Firefox 3.5 – the isocube 系列地址:颠覆网络35天 [...]

    Reply

  44. Hdaes32 wrote on December 22nd, 2009 at 3:40 am:

    Why didn’t you add the non “-moz-” properties? :(
    Damn fanboys…

    Reply

  45. Magne Andersson wrote on December 22nd, 2009 at 2:01 pm:

    @Hdaes32 That’s like asking why they even exist. At the time this was added to Gecko, it wasn’t a finished spec, therefore it must only support the properties with the prefix, just like any other engine/browser. I’m pretty sure the spec still isn’t stable enough.

    Reply

Add your comment