bloqhead
2/28/2012 - 9:57 PM

Pure CSS fix to iOS zoom bug on device rotation

Pure CSS fix to iOS zoom bug on device rotation

/* iPhone */
@media only screen and (width:320px) and (device-width:320px) and (device-height:480px) and (orientation: landscape) {
	body {
		-webkit-transform: scale(0.667);
		-webkit-transform-origin: top right;
		position: absolute;
		right: 0;
		top: 0;
		width: 480px;
	}
}
/* iPad */
@media only screen and (width:768px) and (device-width:768px) and (device-height:1024px) and (orientation: landscape) {
	body {
		-webkit-transform: scale(0.75);
		-webkit-transform-origin: top right;
		position: absolute;
		right: 0;
		top: 0;
		width: 1024px;
	}
}

My approach to fix the iOS bug is documented here:

https://github.com/sergiolopes/ios-zoom-bug-fix

Here I present one experiment with a pure CSS solution, no JS required. It uses width=device-width normally (no device-height hacking) and scales down the page on landscape.

Works fine on all iOS versions.

There's only one problem: on old iOS versions (prior to 4.3.5), the page will get a big empty space at bottom, below the content, when on landscape. Recent iOS versions don't show this behavior.

If you have a solution to this problem on old MobileSafari, please let me know.