This question already has answers here:
Background image not showing on iPad and iPhone
(15 answers)
Closed 3 years ago.
The background picture does not show when I open it on my iPhone or anyone else. On Android devices, it works fine and on a computer in Safari, it also works without a problem.
HTML
<section id="home" class="header">
<div class="v-middle">
<div class="container">
<div class="row">
<div class="caption">
<h5>Hello</h5>
<h1 class="headline-Text">I Am <span id="animated- Text"></span></h1>
</div>
</div>
</div>
</div>
</section>
CSS
#home {
background: url("../images/header-background.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 100vh;
}
background-attachment: fixed has huge performance issue read here.
Browser needs to repaint the image in a new location relative to its DOM elements everytime we scroll, this re-paininting costs more for mobile browsers and that's why most of them has disabled this feature.
I will suggest to use media query and change your rule to background-attachment: scroll; for mobile devices.
If your project still need this feature on mobile devices, consider using a plugin like Scrollmagic
As #ram pandey suggested, I used media queries:
#media only screen and (max-width: 600px) {
#home {
background: #000;
background: url("../images/header-background.jpg") no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 100vh;
}
}
Related
I wanted to give my web page background on which all elements will be so I added this to my CSS file:
body {
background: url("../img/pic.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
And it works as expected on web browsers. The background image is fixed in position and while scrolling, only the elements in body tag moves but not the picture.
BUT that doesn't work for mobile phones...When I open it on my mobile phone that same background picture is shown but zoomed like few times, it won't resize nicely as it looks like when I shrink my web browser on my PC to see a preview on smaller screens.
I tried few pictures, bigger, smaller, different ratios, but nothing helped. I even added
#media screen and (max-width: 479px) {
body {
background: url("../img/pic.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;}}
so I could have a special picture to be shown on mobile devices but no matter which picture I select/upload it always distorts it with that zoom.
I am using bootstrap and still learning. I have some stock files from some templates which I used but searching through them hoping to find somebody CSS which overwrites my own body CSS and zooms on the image but couldn't find any. heh
On phone fixed background work bad on lot of OS.
So try this :
background-attachment: initial;
Or use body:before to set the background.
More solutions here :
background: fixed no repeat not working on mobile
Try this solution:
#media(max-width: 767px) {
body {
background-size: 100%;
background-attachment: initial;
background-position: center;
background-repeat: no-repeat;
}
}
Your problem is propably in declaration of #media tag. It should be #media(max-width: 767px).
I am pretty new to this front-end stuff. I have an image 1200 * 900 px which i am using as a background for my banner. The image seems good on larger screens but when I switch to Apple iPhone 6S from responsive design mode. The background gets cutt off from sides. How do I retain complete image while still on smaller sizes.
index.html
<div class="container-fluid banner">
<div class="row">
<div class="col-md-8 content">
<h1>TThis is a banner image.</h1>
<p>Banner image is the main image we use on our web pages showing what your page is all about.</p>
</div><!--/.col-->
</div>
</div>
style.css
.banner {
background: url(banner.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height: 680px;
position: relative;
}
Some solutions i have tried say to set max-width: 100% on smaller screen size using media queries
#media (max-width: 768px) {
.banner{ max-width: 100%; }
}
But this solution doesn't work. What are my other options to scale this background with screen sizes ?
If you want to display the full picture you should use contain instead of cover.
And if you want to keep cover for larger screens you can change the cover to contain only in your queries.
#media (max-width: 768px) {
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
}
How do I make the background image display on iPhone as it displays on Android?
HTML
<div class="bgimg-1">
<div class="hometoptext ">
<h1 class="text-center">
Africa's First Online Business Lender
</h1>
<div>
<h3 class="thin">Grow faster with South Africa's most innovative online funder</h3>
</div>
<div class="text-center">
<button class="btn btn-primary" (click)="applyNow()">APPLY NOW</button>
</div>
</div>
<div class="bottom-arrow text-center">
</div>
</div>
Background Image not displaying on iPhone
CSS
.bgimg-1 {
background-image: url("img/main_pic2.png");
color: white;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-color: #999;
position:relative;
width:100%;
min-height: 100vh;
top: 0;
}
Image on Android:
Image on iPhone:
iOS Safari has buggy behavior with background-size: cover; +
background-attachment: fixed;
Safari (OS X and iOS) and Chrome do not support background-size: 100%
px; in combination with SVG images, it leaves them at the
original size while other browsers stretch the vector image correctly
while leaving the height at the specified number of pixels.
iOS Safari has buggy behavior with background-size: cover; on a
page's body.
macOS Safari 10 is having frame rate issue with background-size.
Android 4.3 browser and below are reported to not support percentages
in background-size
Ref : Link
A possible solution to this issue is still a pure CSS Fallback
CSS Tricks has three great methods, the latter two are fall backs for when CSS3's cover doesn't work.
HTML
<img src="img/main_pic2.png" id="bg" alt="">
CSS
#bg {
position: fixed;
top: 0;
left: 0;
/* Preserve aspect ratio */
min-width: 100%;
min-height: 100%;
}
The background image is not supported on iOS devices.
Proof link: https://caniuse.com/?search=background-url
I'm on Ubuntu 14.10 developing a website.
Chrome does not render the background correctly. The bottom renders fine, which is the footer that covers the entire width. However the background of the content div is just white.
See the image for reference (I'm new to Stackoverflow and need more rep to post images):
https://www.dropbox.com/s/rqnlg9eh4k7cbv5/white-background-os.png?dl=0
The problem does not occur on OS X or Windows, and the choice of browser does not affect the problem.
I'm using a Alienware M14X R2, so I thought that maybe the Nvidia drivers could be the problem but they are up to date.
Code for the background:
It only happens on this particular site, so I'm guessing something's wrong with my CSS. What's so weird is that it's just with Ubuntu (and I'm guessing several other Linux distributions as well)
Basically I have this:
HTML (homepage.ejs)
<div ui-view ng-app="myApp" id="wrap-content">
<!--Content swapped with Angular and ui-router-->
</div>
CSS:
#media screen and (min-width: 1024px) {
html {
background: url("images/bg.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
div#wrap-content {
width: 900px;
height: 84vmin;
overflow: hidden;
margin: 0px auto;
position: relative;
top: 45px;
}
... a bunch of other stuff
}
Any help is much appreciated.
Okay so I just solved this by accident. Applying the background to HTML caused this weird problem. Changing it to:
body {
background: url("images/bg.jpg") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Solved the issue. Hope this can be useful to anyone ever having the same problem!
I have used twitter bootstrap to make a webpage.
I have inserted an image in background through CSS as following.
<div class="container-fluid">
<div class="row-fluid">
<section id="wrapper">
</section>
</div>
</div>
CSS is as follows:
section#wrapper{
max-width:700px;
background-image:url("img/crane.png");
min-height:525px;
}
When I resize browser size the image is not getting resized according to screen size.
I am not getting how to make it responsive.
So please can any one help me out to resolve this issue.
Thanks in advance.
Try this
section#wrapper{
background:url("img/crane.png") no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
You can use CSS3 background-size with cover as a value and not 100% property for a full page responsive background image for your website
html {
background: url(bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
For more info
You should use the background-size property and set it to cover like in the following shorthand:
div.withBackground {
background: url('http://image.url/img.png') center center cover;
}
read more here
try this background-size:100%;
but not all browser works lower version of browser not recognize background-size