I've been facing this same problem, you can use window.visualViewport
to get only the Viewport Height (minus Keyboard Height)
Here you go.
Just need to use position: fixed
with a header.
.main { position: relative; overflow-x: hidden; } body { overflow-x: hidden; margin: 0; padding: 0; } header { position: fixed; top: 0; left: 0; height: 50px; width: 100%; background: red; color: #fff; } main { margin-top: 50px; height: 100vh; width: 100%; background: green; color: #fff; } footer { height: 50px; width: 100%; background: yellow; color: #fff; }
<div class="main"> <header>This is header</header> <main>This is main section</main> <footer>This is footer</footer> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.