Skip to content

Instantly share code, notes, and snippets.

@unculturedswine
Last active October 3, 2019 21:24
Show Gist options
  • Save unculturedswine/dd960202734eb9647afdd831b847382c to your computer and use it in GitHub Desktop.
Save unculturedswine/dd960202734eb9647afdd831b847382c to your computer and use it in GitHub Desktop.
Mobile Browser 100vh JS/CSS Fix
.selector {
height: 90vh;
height: calc(var(--vh, 1vh) * 100);
}
// This helps us set the screen height to perfect 100%, and accounts for Safari grow/shrink on scroll
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
window.addEventListener('resize', () => {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
});
@unculturedswine
Copy link
Author

This will allow you to set a full height/width element on mobile devices that will prevent an overflow scroll on mobile browsers because acting as intended is a bug for everyone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment