HTML elements affixed to the top of the page using CSS position property set to either fixed or sticky can often work just fine on desktops, but mobile web browsers behave vastly differently due to the resizing nature of the address bar UI.
Setup
This issue happens when the element fixed to the top is nested within an HTML hierarchy, but not when it's placed directly within the body of the document. There are of course some additional assumptions (i.e. styling of the html and body elements), so I'm providing a minimum POC to reproduce the behaviour.
Example
When the website is first loaded, the element with a position fixed to the top of the screen will display below an initially expanded address bar. When the user scrolls the page down, the address bar will shrink to a more compact version, causing viewport to change size. Simultaneously, the element fixed to the top will also change its position and get occluded by the address bar in the process. When the user then scrolls back up, the address bar will expand and consequently, unveil the fixed element. Interestingly, this behaviour isn't "1:1" and subsequently scrolling up and down just enough to occlude and unveil the element results in a net scroll down (on scroll-up, the element is unveiled at a higher rate while on scroll-down the element gets occluded proportionally to the scroll speed).
Reproducing the issue:
<html> <head> <style> html { min-height: 100%; background: lightblue; } body { margin: 0; min-height: 100%; } .navbar { background: lightcoral; height: 5rem; position: fixed; top: 0; width: 100%; } p { font-size: 1.5rem; } </style> </head> <body> <div> <div class="navbar"> <p>navbar</p> </div> </div> <div class="content"> <p>Content</p> <p>Content</p> <p>Content</p> <p>Content</p> <p>Content</p> <p>Content</p> <!-- Add more to fill up the viewport if needed --> </div> </body> </html> Partial fix
Moving the element to be a direct child of the body solves this issue.
Code for the partial fix
<html> <body> <!-- <div> --> <div class="navbar"> <p>navbar</p> </div> <!-- </div> --> <div class="content"> <p>Content</p> <p>Content</p> <p>Content</p> <p>Content</p> <p>Content</p> <p>Content</p> <!-- Add more to fill up the viewport if needed --> </div> </body> </html> 
