Chrome `position:fixed; bottom: 0;` obscured by Android UI

时光总嘲笑我的痴心妄想 提交于 2020-07-22 05:41:12

问题


I have an issue with the following code on Android Chrome. The navigation bars are covering up the element at the bottom of the page.

#test{
  position: fixed;
  bottom: 0;
  width: 100%;
  background: red;
}

Desktop Chrome (correct)

Android Chrome:

Here is a link to the demo: https://codepen.io/EightArmsHQ/pen/EMNaVg

I know that I can increase the bottom: $amount to make it show, but then on other browsers the message won't be flush with the bottom of the browser.

Any ideas on how to make this work?


回答1:


I've tried a solution that I founded in this articule

It's a mix between css and javascript.

First in the css class of the container of the body itself you should define the height property like this:

height: calc(var(--vh, 1vh) * 100);

The vh unit is 1% of the initial containing block, so we can calculate the actual viewport height multiplying our "custom unit" by 100.

Now, the custom unit comes from a javascript variable in the html.

let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`;

In the code above the vh unit is calculated getting the initial viewport size by 1% of it. Then the result is passed to the stylesheet.

And there you go.

The link offers a more detailed explanation and it also show how to handle screen resizing.




回答2:


Try it:

* {
    padding: 0px;
    margin: 0px;
    Box-sizing: Border-box;
}
    body, html {
    width: 100%;
    height: 100%;

}


来源:https://stackoverflow.com/questions/55003456/chrome-positionfixed-bottom-0-obscured-by-android-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!