Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable MobileSafari's content scaling on orientation change?

I'm making a mobile version of my application support site and I have a little WebKit/iOS/HTML/CSS problem here...

I have a page, index.php, with mobile.css file attached. In my <head> tag I have:

<meta name="viewport" content="width=device-width, user-scalable=no, max-scale=1.0" />

My body's css:

body {
    font-family:"HelveticaNeue-Light","Helvetica Neue Light","Helvetica Neue","Helvetica","Lucida Grande",Verdana,Arial,sans-serif;
    margin: 0;
    background: url(../../images/textured_bg.png) repeat;
    color:#454545;
    font-size: 14px;
    text-shadow: rgba(255, 255, 255, 0.5) 0 1px;
    width:100%;
}

Everything works fine in portrait orientation, but when I rotate my iPhone to landscape, Safari scales my content so it looks like in portrait, but a little bigger:

enter image description here

My question: Is there a way, without making custom css for each orientation, to force Safari not to scale my content?

like image 573
akashivskyy Avatar asked Aug 18 '11 18:08

akashivskyy


People also ask

How do I turn off viewport scaling?

To disable pinch-zoom in HTML, simply add <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> to the <head> section.

How do I turn off HTML scaling?

The viewport <meta> tag prevents the user from scaling This means that the URL in question contains a viewport <meta> tag with the attribute user-scalable set to '0' or 'no', which prevents the user from zooming in or zooming out.


1 Answers

The key part to fixing this isn't the meta viewport tag (though that's important, too, but for different reasons). Here's the magic that fixes the text size on orientation change.

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

(I got this from StackExchange's mobile CSS file.)

like image 192
Dave Lancea Avatar answered Oct 02 '22 14:10

Dave Lancea