vh) will not resize in response to the URL bar being shown or hidden. Weird! Perhaps the reason is that background-attachment: fixed relies on the smallest possible viewport while elements rely on the largest possible viewport. That’s because background-attachment calculates a fixed background position relative to the viewport.Įven if we say the body is 100vh, background-attachment: fixed is not exactly in accordance with it. I want to keep the background gradient in a fixed position on scroll, so let’s apply basic CSS styling to the body that does exactly that: body The grey section at the top just indicates the presence of an actual URL bar in Chrome Android.Īnother interesting thing to note is that when background-attachment: fixed is applied, the height is ignored even if we explicitly specify it. We can see it by looking at two different approaches to CSS backgrounds: The issueīefore I show you the fix, let’s examine the issue. I suppose we could call it a “hack” since it’s a workaround in code that arguably we shouldn’t have to do at all. You can ditch this idea completely and let the background scroll on small screens using media queries. What options do you have if you want the body background in a fixed position where it stays put on scroll? background-attachment: fixed in CSS, at best, does not work well in mobile browsers, and at worst is not even supported by the most widely used mobile browsers.
0 Comments
Leave a Reply. |