In relation to z-index
and the stacking order between siblings - by definition only positioned (having position
other than static
) elements obey z-index
values. Positioned elements will always appear above unpositioned.
However, setting transform
and z-index
on an unpositioned element shows weird results which are different on Chrome and Firefox.
Here are 3 unpositioned divs: https://jsfiddle.net/mz29Luwo/
They are stacked according to their order (which is normal).
Now here they are, with transform
set on the second (pink) div, and z-index
-1
: https://jsfiddle.net/mz29Luwo/1/
In Chrome it doesn't change anything,
but in Firefox (49.0, Ubuntu)- it makes the 2nd(pink) div appear below the first one (yellow) - as long as its z-index
is set to a negative value (doesn't matter which one). A similar effect happens if you also set transform
on the 3rd div.
Why is this happening?
Which browser shows the correct behavior?
Are there any other properties (not position
) which can cause similar things?
Is this related to "the stacking context" ? I don't think it should - creating a new stacking context applies to the children of the element, but this is something related to its siblings...
Is there a bug in one of the browsers?
EDIT: Putting transform
also makes the div appear above the other ones - however as said - changing its z-index
doesn't do anything further in Chrome, and in Firefox a negative z-index
does.