Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overflow:auto does not work with CSS3 transformed child elements. Suggested workaround?

Problem: css3 transforms applied to a child element inside a div are ignored by the browser (FF5, Chrome12, IE9) when calculating the scrollHeight and scrollWidth of the containing div's scrollbars when using "overflow: auto;".

<style type="text/css">
div{ width: 300px;height:500px;overflow:auto; }
div img {
-moz-transform: scale(2) rotate(90deg);
-webkit-transform: scale(2) rotate(90deg);
-ms-transform: scale(2) rotate(90deg);
}
</style>    
<div><img src="somelargeimage.png" /></div>

I have put together a small test on jsfiddle showing the undesired behavior.

http://jsfiddle.net/4b9BJ/

Essentially I am trying to create a simple web based image viewer using css3 transforms for rotate and scale and would like a containing div with fixed width/height to be able to scroll to see the full content of the image it contains.

Is there an intelligent way to handle this issue, or even a rough workaround? Any help is appreciated.

like image 264
j0tt Avatar asked Jul 05 '11 18:07

j0tt


People also ask

How do I fix the overflow in CSS?

To change this, set the min-width or min-height property.” This means that a flex item with a long word won't shrink below its minimum content size. To fix this, we can either use an overflow value other than visible , or we can set min-width: 0 on the flex item.

How do you overflow an image in CSS?

To activate the overflow property enclose the image, within a div of a particular width and height, and set overflow:hidden . This will ensure that the base container will retain its structure, and any image overflow will be hidden behind the container.

What does overflow auto do?

overflow: auto The auto value is similar to scroll , but it adds scrollbars only when necessary: You can use the overflow property when you want to have better control of the layout. The overflow property specifies what happens if content overflows an element's box.


1 Answers

I added an extra div to each of the transformations and by setting fixed widths for those divs and clipping overflow I manged to make them the correct size. But then I had to use position: relative and top: blah; left: blah to shift the images into the correct position. http://jsfiddle.net/4b9BJ/7/

like image 153
angrydust Avatar answered Oct 12 '22 04:10

angrydust