在 Android 设备上使用浏览器的元视口标签
我正在开发一个移动网站,它在移动 Safari 上运行得很好。然而,在Android设备上,网站放大太多,但仅限于某些设备。我在我朋友的手机上尝试过,他有运行 Android 2.1 的 HTC Magic,显示正常,但在使用 2.1 的模拟器和我的手机(运行 Android 1.5 的摩托罗拉 Backflip)上显示放大太多。知道为什么会出现不一致吗?
链接是: http://itphosting1.com/dtang/jarritos/
这是元视口标签我正在使用:
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width" />
我认为这可能与设备之间的分辨率和屏幕尺寸差异有关。虽然不太确定如何解决这个问题......
I am developing a mobile web site and it works great on mobile Safari. However, on Android devices, the web site is zoomed in too much, but only on some devices. I tried it on my friend's phone and he has the HTC Magic running Android 2.1 and it shows up ok, but it shows up zoomed in too much on the emulator using 2.1 and my phone which is the Motorola Backflip running Android 1.5. Any idea of why there is an inconsistency?
The link is: http://itphosting1.com/dtang/jarritos/
This is the meta viewport tag I am using:
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width" />
I think it might have to do with resolution and screen size differences between devices. Not really sure how to solve that though...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
把它改成类似的怎么样
How about changing it to something like
我遇到了类似的问题,但解决方案很大程度上取决于我正在处理的网站的设置。在 Android 2.2 及更低版本上,网站无法根据设备正确缩放,媒体查询将响应我的缩放 - 缩小、启动更宽的媒体查询、放大、应用更小宽度的媒体查询。
对于解决方案,就我而言,使用
就足够了。然后我必须考虑的是页面的主容器在 CSS 中设置了明确的宽度。虽然此宽度会响应其他浏览器中视口的宽度,但在本例中不会。我可以在 CSS 中保留显式声明的宽度,只要我确保当第一个媒体查询启动时,主容器将设置为 100% 宽度。基本上,使用 LESS 语法:
I had a similar problem, but the solution was very dependent on the setup of the site I am working on. On Android 2.2 and below, the site wouldn't scale correctly to the device and media queries would respond to my zooming - zoom out, a wider width media query kicked in, zoom back in, and the lesser width media queries were applied.
For a solution, using
<meta name="viewport" content="width=device-width, initial-scale=1">
was enough as far as the viewport meta tag is concerned for me. Then what I had to take into consideration was that the main container of the page had an explicit width set in the CSS. While this width would respond to the width of the viewport in other browsers, it wouldn't in this case. I could leave the explicitly declared width in the CSS, as long as I made sure that when the first media query kicked in, the main container would be set to a 100% width. So basically, using LESS syntax: