英文:
SVH units not working properly in mobile Safari
问题
Mobile Safari无法区分CSS单位svh
和dvh
。这些单位在扩展视口(工具栏收起)时应产生不同的高度,但实际上它们产生相同的高度。
这些单位的Safari支持在大约一年前在WebKit博客中宣布。这些单位在规范CSS Values and Units Module Level 4中有描述。
测试页面
这个片段说明了这个bug,这个网页也是如此。请注意,只有在使用移动版Safari时才能看到这个bug(在iPhone或iPad上,或者使用Xcode附带的模拟器)。
body {
display: flex;
gap: 1em;
margin: 0 2em;
}
div {
border: 5px solid red;
box-sizing: border-box;
width: 5em;
padding-top: 1em;
text-align: center;
}
div:nth-child(1) {
background: cyan;
height: 100vh;
}
div:nth-child(2) {
background: yellow;
height: 100svh;
}
div:nth-child(3) {
background: lime;
height: 100dvh;
}
div:nth-child(4) {
background: pink;
height: 100lvh;
}
<div>100vh</div>
<div>100svh</div>
<div>100dvh</div>
<div>100lvh</div>
期望行为
当工具栏折叠和展开时,唯一会改变大小的元素应该是使用dvh
单位(绿色元素)的元素。其他三个元素应该保持固定大小。
在小视口中查看页面(工具栏展开),使用svh
和dvh
单位的元素都应精确适应视口,而使用lvh
单位的元素应该大于视口。
在大视口中查看页面(工具栏收起),使用dvh
和lvh
单位的元素都应精确适应视口,而使用svh
单位的元素应该小于视口。
换句话说,黄色元素应该是短的,粉色元素应该是长的,而绿色元素应该在短和长之间切换。
实际行为
当工具栏折叠和展开时(使用“隐藏工具栏”菜单选项),使用svh
和dvh
单位的元素都会改变大小。有趣的是,黄色元素立即改变大小,而绿色元素稍后才调整大小。然而,问题在于黄色元素根本不应该改变大小。
这里有一个截图视频,展示了移动版Safari的这个不正确行为。该视频在运行iOS 16.4.1的iPhone上捕获。
英文:
Mobile Safari is not distinguishing between the CSS units svh
and dvh
. These units
should yield different heights with the viewport expanded (toolbars retracted), however instead they are yielding the same height.
Safari support for these units was announced in the WebKit blog around a year ago. These units are described in the specification CSS Values and Units Module Level 4.
Test page
This snippet illustrates the bug, as does this webpage. Note that the bug is only visible when using mobile Safari (on an iPhone or iPad, or using the Simulator which comes with Xcode).
<!-- begin snippet: js hide: true console: true babel: false -->
<!-- language: lang-css -->
body {
display: flex;
gap: 1em;
margin: 0 2em;
}
div {
border: 5px solid red;
box-sizing: border-box;
width: 5em;
padding-top: 1em;
text-align: center;
}
div:nth-child(1) {
background: cyan;
height: 100vh;
}
div:nth-child(2) {
background: yellow;
height: 100svh;
}
div:nth-child(3) {
background: lime;
height: 100dvh;
}
div:nth-child(4) {
background: pink;
height: 100lvh;
}
<!-- language: lang-html -->
<div>100vh</div>
<div>100svh</div>
<div>100dvh</div>
<div>100lvh</div>
<!-- end snippet -->
Expected behaviour
As the toolbars are collapsed and expanded, the only element which should change size is the one sized with <code>dvh</code> units (the lime coloured element).
The other three elements should maintain a fixed size.
When viewing the page in the small viewport (toolbars expanded), the elements sized with <code>svh</code> and <code>dvh</code> should both exactly fit the viewport, and the element sized with <code>lvh</code> should be larger than the viewport.
When viewing the page in the large viewport (toolbars collapsed), the elements sized with <code>dvh</code> and <code>lvh</code> should both exactly fit the viewport, and the element sized with <code>svh</code> should be smaller than the viewport.
To put it another way, the yellow element should be <strong>short</strong>, the pink element should be <strong>long</strong>, and the lime
element should switch between short and long.
Actual behaviour
As the toolbars are collapsed and expanded (using the Hide Toolbar menu option), both the elements sized with <code>svh</code> and <code>dvh</code> change their size. Interestingly, the yellow element changes size immediately and the lime element adjusts a split second later. However, point here is that the yellow element should not be changing its size at all.
Here is a screenshot video illustrating this incorrect behaviour of mobile Safari. Captured on an iPhone running iOS 16.4.1.
答案1
得分: 3
这是浏览器渲染引擎的一个错误,已经向苹果报告。
更新
最初我是通过苹果的反馈助手报告的;通过这种方式提交的报告不会公开。然而,我刚刚发现WebKit有一个公开的Bugzilla系统,所以我已经为这个问题创建了此票。
英文:
This is a bug in the browser’s rendering engine and it has been reported to Apple.
UPDATE
I initially reported this using Apple’s Feeback Assistant; reports lodged this way are not available publicly. However, I have just discovered that WebKit has a public Bugzilla system, so I have created this ticket for the issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论