Bug with transform: scale and overflow: hidden in Chrome

前端 未结 13 1442
不知归路
不知归路 2020-11-28 03:54

Working with CSS3 property transform: scale, I found interesting issue. I wanted to make a little zoom effect for pictures. But when I used for the parent div <

13条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 04:38

    This happens due to composited layers not being clipped by their parent layers. So sometimes you need to bring the parent with overflow:hidden onto its own compositing layer so it can apply overflow:hidden correctly.

    So you must add the CSS property transform: translateZ(0) to the parent element of your transformed element.

    /* add to parent so it is composited on its own layer before rendering */
    .parent-of-transformed-element {
         -webkit-transform:translateZ(0);
         transform:translateZ(0);
    }
    

    Then overflow:hidden will work due to having the transformed element be composited on its own rendering layer like its transformed child.

    Tested on latest Safari and Chrome on iOS and non iOS devices

提交回复
热议问题