iPhone Safari CSS rotation bug

2019-03-22 05:59发布

I have a small mobile phone app that is acting strangely on the iPhone/Mobile Safari. The page renders and works great when it's orientation is vertical. When I rotate the phone horizontally some, but not all elements on the page resize correctly. Some header elements will stay nearly their same size, maybe increasing by 10%, others will double in size.

Has anyone run into this? My first thought was that the css could have a mix of sizes based on ems and px's but finding every size element and converting them to em's didn't change a thing.

2条回答
闹够了就滚
2楼-- · 2019-03-22 06:34

Have you tried including a viewport meta tag, such as this:

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

Otherwise, you could try creating orientation-specific CSS stylesheets and swap them out w/ javascript when the orientation change event fires, but I prefer the meta tag method above.

查看更多
在下西门庆
3楼-- · 2019-03-22 06:39

It's because Mobile Safari on iPhone & iPod Touch does automatic font-size adjustment.

You can disable it with the following css rule,

html {-webkit-text-size-adjust:none}

More info from Safari Reference Library

查看更多
登录 后发表回答