3

In this testcase, without -moz-transform: rotate(-31deg);, the yellow box is visible (as it should be). But if I add this in, the yellow box is not visible despite having a z-index of 999.

Why?

3
  • 1
    Please describe what it is about the "wrong result" that is wrong with it.
    – Spudley
    Oct 14, 2011 at 8:28
  • @Spudley: the 3rd (small yellow) div disappears - its z-index:1 gets ignored, if -moz-transform occurs.
    – SF.
    Oct 14, 2011 at 8:35
  • I added basic formatting and common sense into your question. Oct 14, 2011 at 9:10

1 Answer 1

2

It isn't a bug, it's intentional: the default behaviour when you transform an element is to first flatten the transformed elements into a single layer.

The answer to your question lies in the CSS transform-style property, which overrides this default behaviour, and allows you to maintain the z-index ordering of individual elements nested within the element that is being transformed.

As described in the W3C documentation:

The ‘transform-style’ property defines how nested elements are rendered in 3D space. If the ‘transform-style’ is ‘flat’, all children of this element are rendered flattened into the 2D plane of the element. Therefore, rotating the element about the X or Y axes will cause children positioned at positive or negative Z positions to appear on the element's plane, rather than in front of or behind it. If the ‘transform-style’ is ‘preserve-3d’, this flattening is not performed, so children maintain their position in 3D space.

So to fix your problem, you would theoretically need to add the following to your CSS code for #one: transform-style:preserve-3d;

Unfortunately, "theoretically" seems to be the name of the game here, because it seems that this feature isn't supported by Firefox yet. It apparently is supported by Safari (see this page which details it: http://www.webkit.org/blog/386/3d-transforms/), but my quick attempts to get it working within your fiddle haven't succeeded yet even in Safari.

[EDIT]

I can confirm that the current release of Firefox (v7) does not support transform-style or -moz-transform-style, and nor do the current Beta or Aurora releases.

Information is hard to find, but this bug report on Mozilla.org implies that they're working on it for Firefox version 10.

Given their current release cycle that isn't as far off as it sounds, but nevertheless it is still some time away before you'll be able to use this feature in Firefox. In the meanwhile, the only working solution I can give you is to separate the elements out rather than nesting them, and rotate them independantly.

1
  • According to the docs, firefox implemented it fully and even dropped the -moz- prefix. Still, preserve-3d has no effect on z-index rendering! Nov 7, 2012 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.