Responsive site is zoomed in when flipping between Portrait and Landscape on iPad/iPhone
Asked Answered
E

7

51

I've built a responsive site using Twitter Bootstrap here: http://zarin.me/cce/

The responsive design works great on iPad and iPhone, however when I flip the device from portrait to landscape, the site is zoomed in instead of adapting to the screen (pinching the screen works).

What am I missing? Is this a viewport issue? Here's the only viewport code I have in my :

<meta content="width=device-width, initial-scale=1.0" name="viewport">

Thanks in advance!

Epley answered 22/6, 2012 at 23:35 Comment(0)
P
71

You also want to add the maximum scale

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

UPDATED I agree with some of the comments, the declaration should not limit the scaling by the user as this is bad practice. The below is a better approach and I believe that the zooming bug has long since been fixed by Apple.

<meta name="viewport" content="width=device-width, initial-scale=1">
Photomultiplier answered 24/6, 2012 at 22:8 Comment(6)
try: <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />Borrow
For accessibility reasons, preventing zooming is bad practice. See minneapolisdan's answer for a better solution. You can read more here: alwaystwisted.com/…Pirnot
Preventing zoom is not bad practise. A good responsive design behaves like an app on an iphone, and you can't zoom on an app. Really like the solid feel you get from a site with no zoom. This is the best answer.Rusel
Actually on Safari you can zoom on OSX.Hypothalamus
@Rusel — Preventing zoom is the definition of bad practice when it comes to accessibility. Why else would zoom exist? I have 20/20 vision and still find myself zooming in on text in mobile browsers, usually because two links are positioned too closely. We aren’t talking about native apps here. We’re talking about websites with finicky typography, wildly varying text sizes, and UI elements competing for space. Why any developer would disable this feature just to make their lives easier is a mystery to me.Thorpe
This didn't work. The only thing that worked for me is another post with Matt Stevens answer: https://mcmap.net/q/117668/-preserve-html-font-size-when-iphone-orientation-changes-from-portrait-to-landscapeExieexigency
S
15

While setting the maximum scale to "1" does work, it restricts your users from zooming in on anything within your site. Not ideal for user experience. Try this Javascript instead, iOS-Orientation Change Fix

Subserve answered 17/9, 2012 at 20:3 Comment(2)
This works well, and allows the zoom afterwards. +1 for it! I went with the maximum-scale though, for a few reasons. One, this is js dependent. Two, allowing the zoom breaks the layout in the same way that I was trying to prevent in the first place. I'm hoping that since it's a responsive design users shouldn't have to zoom anyway. Nice solution though!Parenthesize
Its good example but in my case that JS is not working horizontal scroll is comes when I flipped my Ipad @SubserveFuentes
R
12

Set initial-scale=1.0 in the meta:

<meta name="viewport" content="width=device-width,initial-scale=1.0" />

Then set -webkit-text-size-adjust:100%; in the CSS:

body {
  -webkit-text-size-adjust: 100%;
}

This approach doesn't stop a user from zooming in on your website but will ensure that the text doesn't get size adjusted automatically by the browser.

Relentless answered 5/12, 2014 at 8:8 Comment(3)
Got a problem with the iPhone 5 ignoring the viewport meta in an iframe, resulting in an enlarged iframe in landscape mode. But this fix sorts the text size (also in the CSS buttons).Functional
This is the best (also the simplest) solution. Nothing else worked.Muniments
I don't have any iphone or ipad. I tested it in chrom on windows and dev tool set to ipad, I found this problem and this answer helped me.Atomy
R
3

I've seen this happening when one of the containers on the page spills past 100%. The page displays ok in the initial orientation, but when the orientation is changed the extra width somehow becomes in force, causing the page to scale in, and usually leaves a margin on the right or left. Worth checking all your media queries to make sure there is not some trailing padding or margin.

Reminiscent answered 3/4, 2015 at 10:3 Comment(1)
Thanks for making this point. I had an invisible canvas on my page that wasn't resizing on rotate and it was causing this issue.Ovary
D
2

The following works for me and allows users to zoom in

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
Doridoria answered 16/10, 2013 at 12:36 Comment(2)
That didn't work for me I'm afraid, mind you I am testing on iPad v 5.1, apparently this bug is fixed in 6.1+Piscina
worked for me to solve it being zoomed OUT, not zoomed in, as OP's issue.Calculous
G
1

Had exactly this issue on Ipad 3 and IOS 7.1.2

Using maximum-scale=1 fixed it and allows zoom

The js solution did not work

Gluck answered 2/7, 2014 at 12:35 Comment(0)
R
1

If you are facing issue mainly in iPhone-X try <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover" />

That's work for me.

Rewire answered 10/12, 2018 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.