Last active
January 2, 2022 17:48
-
-
Save jarekt/853055b0cc79c1916c485802b7919f67 to your computer and use it in GitHub Desktop.
Fix viewport height size on mobile webkit browsers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
min-height: 100vh; | |
min-height: calc(var(--vh, 1vh) * 100); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fixes vh units on mobile webkit based browsers | |
function fixVhSize() { | |
//get 1% of viewport height | |
let vh = window.innerHeight * 0.01; | |
document.documentElement.style.setProperty('--vh', `${vh}px`); | |
} | |
fixVhSize(); | |
window.addEventListener("resize", fixVhSize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment