For some reason, my div with a background-image gets zoomed in when scrolling on the page when on mobile. I googled it and it seems others had this problem too, but I didn't find a satisfying solution, if any. But, I found this: https://www.w3schools.com/howto/tryhow_css_parallax_demo.htm (from here: https://www.w3schools.com/howto/howto_css_parallax.asp), and it works fine. So what is w3schools doing differently? I checked their code, but I didn't find anything that made a difference.
(FYI, I still have the problem even without the parallax effect from "background-attachment: fixed;" and even without a vh unit for the height).
Here's my code:
HTML:
<div class="landingContainer">
<h1>Welcome to Restaurant</h1>
<h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</h2>
</div>
CSS:
.landingContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-image: linear-gradient(rgba(0,0,0,0.4),rgba(0,0,0,0.4)),
url('/src/components/Home/homeImages/pexels-emre-can-acer-2079438.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
width: 100%;
min-height: var(--vh100);
padding: 1rem;
color: white;
text-align: center;
overflow-wrap: anywhere;
}
.landingContainer h1 {
font-size: clamp(2.2rem, 2.0058rem + 1.2427vw, 3rem);
/* https://css-tricks.com/linearly-scale-font-size-with-css-clamp-based-on-the-viewport/#for-those-who-dont-mind-that-edge-case */
font-weight: 600;
margin: 1em 0 .5em;
color: white;
}
.landingContainer h2 {
font-size: clamp(1rem, 0.9892rem + 0.0693vw, 1.1rem);
font-weight: 300;
width: 85%;
max-width: 45ch;
line-height: 1.6;
}
Thank you!
Update: see here for a video: https://imgur.com/a/ZFWgdqr