Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome android height/scroll issue with footers and the address bar

So here is an interesting situation I have come across. You are on Chrome for android, when you scroll the body the address bar runs away and hides. Great!

Now you want to add a footer to your page that sticks to the bottom. You do the following:

html {
  margin:0;
  padding:0;
  height:100%;
}

body {
  margin:0;
  padding:0;
  height:100%;
}

#contentWrap {
  margin:0;
  padding:0;
  padding-bottom:4em;
  min-height:calc(100% - 4em);
  position:relative;
}

#footer {
  margin:0;
  padding:0;
  height:4em;
  width:100%;
  position:absolute;
  bottom:0;
  
  background:#262626;
}
<html>
<body>
  
  <div id="contentWrap">
    <div id="footer">
    </div>
  </div>
  
</body>
</html>

This works brilliantly, the footer will always stick to the bottom of the page regardless of content size or view-port scale.

However! Running this on a mobile design and testing in Chrome Android I found that setting the body to an explicit size, it will only scroll "content within" causing the address bar to stick around. Overflowing content is just set to default scroll in other words. Noticing this I tried changing it to min-height so that it will always either be the size of the view-port if no content is available to fill it, or change height if there happens to be many lines of content.

Doing this however causes the contentWrap to base its height on the content rather than the parent element ie. <body>. So your footer now floats instead of sticking to the bottom.

I have played around with many combinations and cant seem to get what I want. Seems you have to live with either a sticky address bar OR a floating footer.

Please any ideas or thoughts on this would be appreciated.

like image 468
Mollen101 Avatar asked Oct 16 '14 11:10

Mollen101


1 Answers

Thanks but no that does not work in this situation.

Earlier today though whilst working on another project it hit me like a wet fish.

Remove dimensions from <html>.

Then add 100vh to your <body> instead of 100%

(making sure to only target mobile devices and not desktops)

Then it works perfectly! xD

Though Chrome is awesome imo. The little address hide on scroll has given me numerous headaches over the past few months.

like image 60
Mollen101 Avatar answered Oct 09 '22 20:10

Mollen101