Mobile Safari - viewport device-height not working as expected

烈酒焚心 提交于 2021-02-09 08:19:51

问题


I have a web app that I'm trying to run on an iPad 3. When I pull it up, the app is allowing vertical scroll when it shouldn't be. I've gone through the same process with other web apps without any issues, and am not sure what I am missing this time around.

Inside head element of my html, I have the following meta tags:

    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, minimum-scale=1, maximum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi">
    <meta name="apple-mobile-web-app-capable" content="yes">

In my CSS:

    html, body { width: 100%; height: 100%; overflow: hidden; }

Trying to debug this issue in weinre and discovered that the document width and height are somehow equal, when height show be much smaller (in landscape).

    $(document).width();  // returns 1024
    $(document).height(); // returns 1024

Searching around SO, other answers have been to supply a viewport meta tag, which I'm already doing. Can someone point me to a solution here?


回答1:


It looks to me like you are using too many properties of viewport that might conflict with each other. Apple suggests to set few of them or one and test in isolation as others are automatically inferred.

Bootstrap in its basic template recommends to set only width and initial-scale.

I would be very careful with maximum-scale or anything restricting user's zooming as it forces the user into uncomfortably small (or large) text.




回答2:


Okay, for some reason this worked when I removed "height=device-height" from the viewport meta tag. Not sure why since I literally just copy and pasted this tag from another app that worked just fine. Working viewport:

<meta name="viewport" content="user-scalable=no, initial-scale=1, minimum-scale=1, maximum-scale=1, width=device-width, target-densitydpi=device-dpi">


来源:https://stackoverflow.com/questions/23963052/mobile-safari-viewport-device-height-not-working-as-expected

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