Mobile Safari Viewport - 防止水平滚动?

发布于 2024-10-30 19:24:03 字数 560 浏览 3 评论 0原文

我正在尝试为移动 Safari 配置视口。使用视口元标记,我试图确保没有缩放,并且不能水平滚动视图。这是我正在使用的元标记:

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

在我的 iPhone 上,当我加载页面时,看起来不错:

screenshot

但我可以水平滚动,使其看起来像这样(这是我能到达的最右边的位置:

screenshot

当我将其切换到横向视图时,页面按预期呈现,锁定水平滚动位置,

我试图弄清楚如何使该页面根本不水平滚动。是否有可能推动一些页面元素。我什至不希望通过正确的视口设置来实现这一点,但我在这里抓住了救命稻草。

I'm trying to configure a viewport for mobile Safari. Using the viewport meta tag, I am trying to ensure that there's no zooming, and that you can't scroll the view horizontally. This is the meta tag I'm using:

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

On my iPhone when I load the page, it seems to look okay:

screenshot

But I can scroll horizontally, so that it looks like this (this is as far to the right as I can go:

screenshot

When I swing it into landscape view, the page renders as expected, locking the horizontal scroll position.

I'm trying to figure out how to make this page not scroll horizontally at all. Is it possible that I've got some page element pushing the content out? I wouldn't even expect that to be possible with a correct viewport set, but I'm grasping at straws here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

闻呓 2024-11-06 19:24:04

来晚了,但我刚刚遇到了类似的问题,我在 iPhone 5 上水平滚动,该网站实际上显示为两倍的宽度,而右手半边完全是空的。

事实上,我只需要将视口元标记从: 更改

<meta name='viewport' content='width=device-width, maximum-scale=1.0, minimum-scale=1.0' />

为:

<meta name='viewport' content='width=device-width, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0' />

添加“初始比例”将其锁定,以便它仅按预期垂直滚动。

Late to the party here, but I just had a similar problem where I had horizontal scrolling across an iPhone 5, the site was effectively showing as double the width, with the right hand half completely empty.

In fact, I just needed to change the viewport meta tag from:

<meta name='viewport' content='width=device-width, maximum-scale=1.0, minimum-scale=1.0' />

to:

<meta name='viewport' content='width=device-width, maximum-scale=1.0, minimum-scale=1.0, initial-scale=1.0' />

Adding the 'initial-scale' locked it down so that it only scrolled vertically as expected.

离笑几人歌 2024-11-06 19:24:04

这将防止任何元素将内容推出:

body div {overflow: hidden ;}  @ media queries 

This will prevent any elements pushing content out:

body div {overflow: hidden ;}  @ media queries 
清晰传感 2024-11-06 19:24:04

尝试这个变体:

html, body{
  overflow-x: hidden;
}

Try this variant:

html, body{
  overflow-x: hidden;
}
眼波传意 2024-11-06 19:24:03

我是否有可能有一些页面元素将内容推出?

是的,确实是这样。视口设置仅定义可见视口区域,但不处理关闭横向平移。

因此,为了避免这种情况发生,请在包含内容的元素上设置溢出:隐藏,否则避免元素溢出。

注意:其他移动浏览器也支持视口元标记一段时间了,因此您也需要在这些浏览器中进行测试。

Is it possible that I've got some page element pushing the content out?

Yes, that is indeed the case. The viewport setting only defines the visible viewport area but does not deal with turning off sideway panning.

So, in order to avoid this from happening, set an overflow:hidden on the element that contains your content, or else, avoid elements from overflowing.

NB: other mobile browsers also support the viewport meta tag since a while, so you'll want to test in those as well.

停顿的约定 2024-11-06 19:24:03

body { 溢出-x: 隐藏; } 也有效。

body { overflow-x: hidden; } also works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文