简体   繁体   English

如果在 iOS Safari 15 上查看,如何将 position 元素绝对底部?

[英]How to position elements absolute bottom if viewing on iOS Safari 15?

I have a screen height of 100vh with an element that is positioned in the bottom corner of the viewport.我的屏幕高度为 100vh,元素位于视口的底角。

If the user views on the latest iOS Safari, the search bar by default covers up that element.如果用户查看最新的 iOS Safari,默认情况下搜索栏会覆盖该元素。

Is there a way to adjust the position based on this particular browser?有没有办法根据这个特定的浏览器调整 position?

You can use env(safe-area-inset-bottom) , which represents the search bar on iOS. This is by default set to 0.您可以使用env(safe-area-inset-bottom) ,它代表 iOS 上的搜索栏。默认设置为 0。

Read more: https://developer.mozilla.org/en-US/docs/Web/CSS/env阅读更多: https://developer.mozilla.org/en-US/docs/Web/CSS/env

body {
     padding-bottom: env(safe-area-inset-bottom);
}

You want the browser to dynamically adapt to the rendered space.您希望浏览器动态适应渲染空间。 To do so, you should use the dvh unit instead of the vh unit.为此,您应该使用dvh单位而不是vh单位。

This unit get updated whenever the browser rendering space get updated (you have an equivalent for all basic viewport units: dvw , dvmin , dvmax ).每当浏览器渲染空间更新时,该单位都会更新(您拥有所有基本视口单位的等效项: dvwdvmindvmax )。

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

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