Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android viewport setting "user-scalable=no" breaks width / zoom level of viewport

I am working on a web app which has a width of 640px.

In the document head I set

  <meta name="viewport" content = "width=640, user-scalable=no" />

so the content is nicely displayed and stretched horizontally.
This works perfectly on iOS but in Android the browser opens the website zoomed in so the user has to double click to zoom out and the entire page.

When I change the viewport setting to leave out the user-scalable tag like this:

<meta name="viewport" content="width=640" />

the Android browser adjusts nicely to the 640px - so it works.
The problem however now is, that users can zoom in and out on Android and iOS since the user-scalable tag is not set.

How can I forbid the scaling and at the same time set the viewport width to 640px on Android?

like image 864
Horen Avatar asked Oct 04 '12 09:10

Horen


People also ask

What is user scalable in viewport?

The user-scalable="no" parameter for the <meta name="viewport"> element disables browser zoom on a web page. The maximum-scale parameter limits the amount the user can zoom. Both are problematic for users with low vision who rely on browser zoom to see the contents of a web page.

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.

What does meta name viewport content width device width initial scale 1.0 mean and why is it important?

Setting The Viewport The width=device-width part sets the width of the page to follow the screen-width of the device (which will vary depending on the device). The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser.

What is the purpose of viewport meta tag?

Setting the viewport meta tag lets you control the width and scaling of the viewport so that it's sized correctly on all devices.


1 Answers

Trying rendering the viewport meta tag like so:

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

Setting scale settings will set user restrictions on how far they can zoom, and so if you set the initial and maximum to the same amount, this should fix the problem.

UPDATE: I was able to fix my bug for android devices all together by setting the below:

<meta name="viewport" content="width=640px, initial-scale=.5, maximum-scale=.5" />

I also noticed that some content, such as p tags were not flowing across the screen, so the hack for that would be to add the background-image property with empty string to any content that is stuck and is not going across the layout view. Hope this helps this time for you.

like image 98
Ben Sewards Avatar answered Nov 09 '22 14:11

Ben Sewards