CSS background-size: cover replacement for Mobile Safari
I've had this issue on a lot of mobile views I've recently built.
My solution is still a pure CSS Fallback
http://css-tricks.com/perfect-full-page-background-image/ as three great methods, the latter two are fall backs for when CSS3's cover doesn't work.
HTML
<img src="images/bg.jpg" id="bg" alt="Sample Image">
CSS
#bg {
position: fixed;
top: 0;
left: 0;
/* Preserve aspect ratio */
min-width: 100%;
min-height: 100%;
}
How to set body background image as cover for ios devices
It should be background-size: cover;
and not background-image
. Also, you should be using browser
prefixes as the property was released under CSS3 Specification1..
body {
background-image: url(#);
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
}
1. Browser Support
Background size cover not working on longer pages on mobile
If I've understood correctly, you want the background image to at least fill the viewport but if the body is higher than that you want it to fill the whole body.
Therefore, tell it that the min-height of the body must be 100vh and don't set an actual height, let it work it out from the content.
I'm assuming in this snippet that you want just one copy of the background, centered and using size cover (so it may get cropped top/bottom or at the sides depending on relative aspect ratios).
A dummy div is put in the snippet to ensure we get scrolling.
body {
background-image: url("https://via.placeholder.com/500");
background-size: cover;
background-repeat: no-repeat no-repeat;
background-position: center center;
margin: 0;
padding-left: 5vw;
padding-right: 5vw;
min-height: 100vh;
width: 90vw;
font-family: system-ui;
overflow-x: hidden;
font-size: 1.3rem;
}
div {
height: 350vh;
}
<div></div>
background-size: cover does not cover mobile screen
After hours of trying different things, adding min-height: 100%;
to the bottom of html
under the { background:... }
worked for me.
Related Topics
Why Anchor Tag Does Not Take Height and Width of Its Containing Element
Maintain Image Aspect Ratio When Changing Height
Ordered List (Html) Lower-Alpha With Right Parentheses
Best Approach to Real Time Http Streaming to Html5 Video Client
What Values Can Appear in the "Selected" Attribute of the "Option" Tag
What Is Initial Scale, User-Scalable, Minimum-Scale, Maximum-Scale Attribute in Meta Tag
Youtube Embedded Video: Autoplay Feature Not Working in Iphone
How to Style Dt and Dd So They Are on the Same Line
Floating an Image to the Bottom Right with Text Wrapping Around
Using Display Inline-Block Columns Move Down
Setting the Character Encoding in Form Submit For Internet Explorer
Why Would a Developer Place a Forward Slash At the Start of Each Relative Path
Make an Image Responsive - the Simplest Way
How to Access a Mobile'S Camera from a Web App
Assign an Initial Value to Radio Button as Checked
How to Disable Google Translate from HTML in Chrome