简体   繁体   English

Chrome for iOS与<style>height: 100vh;</style>

[英]Chrome for iOS vs. <style>height: 100vh;</style>

Chrome for iOS hides its address bar when the user scrolls up. 当用户向上滚动时,Chrome for iOS隐藏其地址栏。 This feature does not work well with 100vh (or any vh unit) because as the toolbar shrinks, the viewport height changes and thus the size of the element changes. 此功能不适用于100vh (或任何vh单位),因为当工具栏缩小时,视口高度会发生变化,因此元素的大小也会发生变化。 I have a cover image with 100vh and it causes a very noticeable jitter as the length of the entire page grows or shrinks. 我有一个100vh的封面图像, 100vh整个页面的长度增加或缩小,它会引起非常明显的抖动。

The problem exists for any height set with vh , I think. 我认为对于用vh设置的任何高度都存在问题。

I can (and probably will) resort to javascript to set my cover image height, but I'd prefer to use vh . 我可以(可能会)使用javascript设置封面图像的高度,但是我更喜欢使用vh

Any clever ideas? 有什么聪明的主意吗?

I'd recommend using 100% instead of 100vh - you can add this... 我建议使用100%而不是100vh-您可以添加此...

body{
 position: absolute;
 width: 100%;
 height: 100%;
 margin: 0;
}

From there, any element without another wrapper that has its own height will be able to fill the full screen just using width and height at 100%. 从那里开始,任何没有另一个具有自己高度的包装的元素都将能够使用100%的宽度和高度填充整个屏幕。 Example below! 下面的例子!

https://codepen.io/will0220/pen/KXqoGZ https://codepen.io/will0220/pen/KXqoGZ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM