Why won't my viewport tag properly use device width (no zoom) on most mobile devices?

℡╲_俬逩灬. 提交于 2019-12-05 16:18:08

After much testing and continued searching, I came up with a fix that seems to be very effective. Another solution I saw to a similar problem proposed the following:

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

This, at first, seemed like a decent solution as it worked on most phones. It bugged me a little bit though because it obviously isn't geared specifically towards working with any device width. That answer can be found here:

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

This solution worked on most mobile devices, but on some it was ineffective causing the display to be using incorrect zoom.

I believe the reason why the solution above is not effective is because not all mobile devices use a base 320 for zoom. So when device-width isn't working, this causes the constraints to be inconsistent.

I tried a bunch of different things, but then ultimately tried the following which (so far) seems highly effective:

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

I believe the difference in this tag is that it tells the device to use it's native dimensions, but then adds a scale factor that tells it to not zoom in as much as it would normally.

I never was able to find any CSS adjustments that solved the problem, and I welcome any other answers in the future that may add further clarification to the problem/solution.

One other thing I'd like to add, is that an alternative meta tag that may be more effective for larger devices (tablets, which the site in this problem was not designed for), may be to set maximum scale instead of using user-scalable. Like this:

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

EDIT / Update 2018:

This question still gets quite a few hits even though it's a very dated problem. Certainly in hindsight and after much more experience with responsive, I can say that both the initial problem and the solutions were based around stop-gap issues that resulted from poorly constructed responsive CSS and HTML.

While the answers here may help future visitors solve for issues when it comes to retro-fitting more dated code, I would highly recommend that any new development conform to the latest in responsive standards. If your markup and CSS conforms, there are very few reasons why you would ever not want the standard meta for viewport in responsive (below):

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

I just removed initial-scale=1 and suddenly Android on Chrome and Silk on a Kindle both worked perfectly, site width matched to screen width in both orientations.

<meta name='viewport' content='width=device-width'>

I haven't tested on IOS, but I'll add an IOS specific hack if I need to.

Skippy le Grand Gourou

Check this answer. In short :

<meta name="viewport" content="width=device-width; target-densityDpi=device-dpi;" />

Great Stuff, however, I have discovered that if you are on a desktop and the viewport is set to a static width the backgrounds may not render on the portions of the screen not shown when you horizontal scroll.

To fix this for non-responsive pages simply add a min-width to the body.

body {
    min-width: 960px;
}

Note, this is in addition to setting the viewport a static width

<meta name=viewport content="width=960">  

Anyone looking for a fix in the future, stay with content="width=device-width, initial-scale=0.5" BUT adjust the initial-scale= until it works. I built a site that worked fine on different resolution monitors but was absolutely horrid on mobile. Try 0.5 then scale downwards .1 at a time until it works. On two Android phones 0.3 worked perfectly for me.

I had an issue with bootstrap 4.3.1 looking like a scaled down version of a tablet view on mobile using this meta tag setup:

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

so then i used the meta tag below to fix on mobile:


<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">

now it looks like bootstrap 4 should look cross device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!