CSS3 Transformations showing content outside overflow:hidden region in Firefox/Android

Some time back I was implementing a functionality for Firefox browsers on Android devices and I found a strange problem – For Firefox > 18 on Android devices if I move an element using CSS3 Transformations inside a parent container with overflow:hidden, then part of the element being moved is displayed outside the overflowed region. It seems like when you move the element it just discards the overflow:hidden property and everything is revealed rather. Normally the content outside overflow:hidden should be cut off from view.

I have a simple demo http://rialab.jbk404.site50.net/ffandroidissue/ – an image which is bigger than the container div is moved using CSS3 Transformations. The  div has a overflow:hidden set to it. There are two buttons. Click on them to see the various results. The first button causes the issue whereas the second button resolves it.

So this is what causes the issue – moving the image using CSS3 Transformations (for eg. transform:translateX(value);) inside a container with overflow:hidden

And this is what solves it – strange !!
Adding a background color and an opacity to the container element like this,

-moz-perspective: 1000px;
overflow: hidden;
width: 100px;
height: 50px;
display: block;

Check out the demo in Firefox on an Android device. I am not sure if anybody has encountered this situation. But this definitely seems to be a bug in Firefox for Android’s. This is not seen for other browsers.


15 thoughts on “CSS3 Transformations showing content outside overflow:hidden region in Firefox/Android

  1. Great! I was searching a lot to find a workaround for this, also posted a question on SO (http://stackoverflow.com/questions/15405054/firefox-mobile-element-animated-with-translate3d-flows-out-from-parent-containe)
    Your solution with opacity kind of works (I already had background on the element), but still has some rendering problems.
    Btw, my problem occurs with the mobiscroll picker, it can be reproduced here: http://demo.mobiscroll.com/datetime#display=inline

  2. This isn’t a bug, it has to do with paint layers – i.e. GPU layers. A paint layer (that lies above everything else) is created by using transforms OR opacity (which explains why your workaround works).

    1. Yep! So I add a style transform: translate(0,0); to the container element to fix this problem, and it works perfectly!

  3. For me, the Opacity and Background were unnecessary, and it didn’t work without the “position: absolute”. I tried removing just this part to test, and indeed the “absolute” is what makes the “overflow: hidden” work in my case. If it matters, I’m using a DIV container with a TABLE inside, and I’m using all three translations with all three rotations.

  4. As said before it have to do with the GPU painting layers, it’s not a bug. To fix it you just need to force the overflow: hidden element to be painted by the GPU too. So if you use a translate(0,0), translate3d(0,0,0) or opacity you will force the element being painted by GPU.

Leave a Reply to joseph Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.