Set the CSS height
of your root container element (let's call it rootElement
) to the height of the view port:
.root-element {
height: 100vh;
}
Then, when the page did render, run this code to update rootElement
height to the view port height minus the size of the browser UI bars (for example, on iOS Safari: top address bar, bottom navigation bar…):
const rootElement = document.querySelector(".root-element")
const viewPortH = rootElement.getBoundingClientRect().height;
const windowH = window.innerHeight;
const browserUiBarsH = viewPortH - windowH;
rootElement.style.height = `calc(100vh - ${browserUiBarsH}px)`;
This solution sets the size of your root container to what is available, but it also keep the possibility for the browser to adapt rootElement
height when the window is resized (when used on a desktop, for instance).