transform:scale() breaking my z-index order

岁酱吖の 提交于 2020-01-02 06:23:28

问题


I did setup an HTML page where I use z-index to set the elements "visual" order. It works as expected; but breaks when I use transform: scale().

#blocks-both{
    transform: scale(0.9);
}

I make a simplified example here : http://codepen.io/anon/pen/LNYrar

I read a lot of messages regarding this particular problem, but I can't find a solution to make my design work. I guess I don't understand something regarding this.

Could someone help ?

Thanks !


回答1:


This is a known issue:

  • css z-index lost after webkit transform translate3d
  • webkit-transform breaks z-index on Safari
  • webkit-transform overwrites z-index ordering in Chrome 13

You can read more about it here as it offers in depth explanation.

In addition to opacity, several newer CSS properties also create stacking contexts. These include: transforms, filters, css-regions, paged media, and possibly others. As a general rule, it seems that if a CSS property requires rendering in an offscreen context, it must create a new stacking context.

You could avoid this issue by moving the transform properties from #blocks-both to #block-main and #block-sidebar like this:

#block-main, #block-sidebar {
  transform: scale(0.9);
}

#block-main {
  transform-origin: 100% 0;
}

#block-sidebar {
  transform-origin: 0 0;
}

I've also edited your example.



来源:https://stackoverflow.com/questions/35681829/transformscale-breaking-my-z-index-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!