在 Android 设备上使用浏览器的元视口标签

发布于 2024-10-20 01:07:39 字数 498 浏览 2 评论 0原文

我正在开发一个移动网站,它在移动 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

负佳期 2024-10-27 01:07:39

把它改成类似的怎么样

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

How about changing it to something like

<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width" />
梦幻之岛 2024-10-27 01:07:39

我遇到了类似的问题,但解决方案很大程度上取决于我正在处理的网站的设置。在 Android 2.2 及更低版本上,网站无法根据设备正确缩放,媒体查询将响应我的缩放 - 缩小、启动更宽的媒体查询、放大、应用更小宽度的媒体查询。

对于解决方案,就我而言,使用 就足够了。然后我必须考虑的是页面的主容器在 CSS 中设置了明确的宽度。虽然此宽度会响应其他浏览器中视口的宽度,但在本例中不会。我可以在 CSS 中保留显式声明的宽度,只要我确保当第一个媒体查询启动时,主容器将设置为 100% 宽度。基本上,使用 LESS 语法

@containerWidth: 1080px;

#page {
    width: @containerWidth;
}

@media screen and (max-width: @containerWidth) {
    #page {
        width: 100%;
    }
}

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:

@containerWidth: 1080px;

#page {
    width: @containerWidth;
}

@media screen and (max-width: @containerWidth) {
    #page {
        width: 100%;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文