Last active
July 29, 2023 05:18
-
-
Save TomDawson/624763cea7cf4392c239b6845a3831ba to your computer and use it in GitHub Desktop.
Fix for background image shifting and revealing white space when mobile URL/menu collapses
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
body::before { | |
content: ''; | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100vh; | |
background-image: url(../images/background-dark.jpg); | |
background-color: #171a21; | |
background-size: cover; | |
z-index: -1; | |
} |
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
/* | |
Dynamic will adjust the height based on whether mobile url/menu section is collapsed or not, but can result in janky layout shift | |
Large sets height assuming the menu is collapsed, and can result in content being taller than intended | |
Small assumes the menu is expanded and can result in content being shorter than intended | |
The best option depends on your use case | |
*/ | |
div { | |
/* Dynamic Viewport Height */ | |
min-height: 100dvh; | |
/* Large Viewport Height */ | |
min-height: 100lvh; | |
/* Small Viewport Height */ | |
min-height: 100svh; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worth noting that using updated.css could be more appropriate depending on your situation, but style.css may have better browser compatibility compared to dvh/lvh/svh