视觉视口和布局视口之间的区别?

发布于 2024-11-15 08:44:24 字数 66 浏览 2 评论 0原文

iPhone/iPad 等移动设备的视觉视口和布局视口有什么区别?

网上查了很多资料,但还是不太明白。

What is the Difference between visual viewport and layout viewport for a mobile device like iPhone/iPad?

I have gone through a lot of online resources, but am still unclear about it.

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

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

发布评论

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

评论(3

っ〆星空下的拥抱 2024-11-22 08:44:24

视觉视口是当前在屏幕上显示的页面的一部分。

布局视口可以比视觉视口宽得多,并且包含出现和不出现在屏幕上的元素。

将布局视口想象为一个不会改变大小或形状的大图像。现在想象一下你有一个较小的框架,通过它可以看到大图像。小框架被不透明材料包围,这会遮挡您的视线,只看到大图像的一部分。您可以通过框架看到的大图像部分是视觉视口。您可以在按住框架的同时远离大图像(缩小)以立即查看整个图像,也可以靠近(放大)以仅查看一部分。您还可以更改框架的方向,但大图像(布局视口)的大小和形状永远不会改变。

有关该问题的最佳处理方法,请参阅:http://www.quirksmode.org/mobile/viewports2 .html

The visual viewport is the part of the page that’s currently shown on-screen.

The layout viewport can be considerably wider than the visual viewport, and contains elements that appear and do not appear on the screen.

Imagine the layout viewport as being a large image which does not change size or shape. Now imagine you have a smaller frame through which you look at the large image. The small frame is surrounded by opaque material which obscures your view of all but a portion of the large image. The portion of the large image that you can see through the frame is the visual viewport. You can back away from the large image while holding your frame (zoom out) to see the entire image at once, or you can move closer (zoom in) to see only a portion. You can also change the orientation of the frame, but the size and shape of the large image (layout viewport) never changes.

For a great treatment of the issue, see: http://www.quirksmode.org/mobile/viewports2.html

白衬杉格子梦 2024-11-22 08:44:24

关于这两者的非常好的解释可以在此处找到。

总之:

视觉视口

视觉视口是当前在屏幕上显示的页面的一部分。用户可以滚动以更改他看到的页面部分,或缩放以更改视觉视口的大小。

布局视口

但是,CSS 布局(尤其是百分比宽度)是相对于布局视口计算的,布局视口比视觉视口宽得多。

因此,该元素最初采用布局视口的宽度,并且您的 CSS 被解释为屏幕明显比手机屏幕宽。这可以确保您网站的布局与桌面浏览器上的布局相同。

布局视口有多宽?这因浏览器而异。 Safari iPhone 使用 980px、Opera 850px、Android WebKit 800px 和 IE 974px。

简而言之,布局视口一般是屏幕完全缩小时视口的宽度。

A very good explanation of the two is found here.

In summary:

Visual viewport

The visual viewport is the part of the page that’s currently shown on-screen. The user may scroll to change the part of the page he sees, or zoom to change the size of the visual viewport.

Layout viewport

However, the CSS layout, especially percentual widths, are calculated relative to the layout viewport, which is considerably wider than the visual viewport.

Thus the element takes the width of the layout viewport initially, and your CSS is interpreted as if the screen were significantly wider than the phone screen. This makes sure that your site’s layout behaves as it does on a desktop browser.

How wide is the layout viewport? That differs per browser. Safari iPhone uses 980px, Opera 850px, Android WebKit 800px, and IE 974px.

In short, the layout viewport is generally the width of the viewport when the screen is zoomed all the way out.

冰魂雪魄 2024-11-22 08:44:24

布局视口

无论方向或缩放级别如何,其测量值始终相同,仅取决于设备/浏览器窗口。

视觉视口

它会变化(例如缩放时)。这是在任何给定点实际显示在屏幕上的页面部分。

两种布局的视频示例

布局视口:小地图中的绿色区域。
视觉视口:小地图中的红色框。

布局视口与视觉视口(视频)

在移动/平板电脑设备上

情况下情况可能会稍微复杂一些,因为为了提供“完整的网络”体验,许多移动设备返回假的更高的布局视口尺寸。

例如,经典 iPhone 默认报告的布局视口宽度为 980 像素。这意味着,如果您在 iPhone 上创建 320 像素的元素,它只会填充大约三分之一的屏幕空间。

但是,对于使用媒体查询针对窄屏幕进行优化的页面来说,这种机制不太好

当我们创建响应式网站时,使用视口元标记非常有用,它可以让我们控制许多设备的缩放和布局视口(使用真实尺寸,而不是报告的假尺寸)。

<meta name="*viewport*" content="*width=device-width*, initial-scale=1, maximum-scale=1" />

视口元标记示例

提示:如果您使用手机或平板电脑浏览此页面,您可以
单击下面的两个链接即可查看差异。

没有视口元标记使用视口元标记

没有视口元标记 使用视口元标记

Layout viewport

Its measurements are always the same regardless of orientation or zoom level, just depend on the device/browser window.

Visual viewport

It varies (when zoomed for example). This is the part of the page that’s actually shown on the screen at any given point.

Video example of both layouts

Layout viewport: The green area in the minimap.
Visual viewport: The red box in the minimap.

Layout viewport vs visual viewport (video)

On Mobile/Tablet devices

On mobile devices, things can be a little more complicated by default, because in order to allow a “full web” experience, many mobile devices return a fake higher layout viewport dimensions.

For example, the classic iPhone by default reports a layout viewport width of 980px. This means that if you create a 320px element on the iPhone, it will fill up only about a third of the screen real estate.

However, this mechanism is not so good for pages that are optimized for narrow screens using media queries.

When we are creating responsive websites is very useful to use the viewport meta tag, which lets us control the scaling and layout viewport of many devices (using the real dimensions, not the fake reported).

<meta name="*viewport*" content="*width=device-width*, initial-scale=1, maximum-scale=1" />

Examples of viewport meta tag

Tip: If you are browsing this page with a phone or a tablet, you can
click on the two links below to see the difference.

Without the viewport meta tag With the viewport meta tag

Without the viewport meta tag With the viewport meta tag

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