Background size on iOS - html

I've spent the morning doing research on the following issue. I'm making a one page site, using a lot of images. I'm aware that Safari is known for its weird handling of background-attachment:fixed, but that's working fine; my problem is background-size:cover is not working in conjunction with fixed.
I have 5 pages, all of which have a height or min-height of 100%. The last page is fixed like this:
#div5 {
height:100%;
width:100%;
position: relative;
background-image: url("img/background.jpg");
background-attachment:fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
On iOS (in both Chrome and Safari) the background image is scaled to cover the full webpage, so it's really stretched.
At the same time, page 4 has the following css:
#div4 {
min-height:100%;
width:100%;
background:url(img/portfoliobg.jpg);
overflow: auto;
background-size: cover;
}
and this works like a charm.
So, something makes the browser behave really weirdly when combining fixed and cover. Does anyone have a solution to this?

Use another div with position:fixed to make the background fixed.
Like this:
http://codepen.io/anon/pen/OVebNg
JADE
.fixed
.bgcover
SCSS
.fixed {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
.bgcover {
background-image: url('http://globe-views.com/dcim/dreams/winter/winter-04.jpg');
background-size: cover;
width: 100%;
height: 100%;
}
}
Hope this help.

Short answer: you can’t (for now).
You can play with #media screen and (max-width: 1024px) {} but for now iPad Pro have resolution more then ordinary monitors.
I offer you to disable fixed attachment for mobiles via this way:
Main CSS file:
.parallax {
background-attachment: fixed;
background-size: cover;
}
Main HTML
<script type="text/javascript">
if (navigator.userAgent.match(/(iPad|iPhone|iPod|Android|Silk)/gi)) {
document.write("<link rel=\"stylesheet\" href=\"fixparallax.css\" />");
}
</script>
Additional fixparallax.css
.parallax {
background-attachment: scroll !important;
}

Related

Background-size doesn't work on mobile

I really don't know why this is happening, I guess I'm tired, but the question is that the "background-size" doesn't work on my mobile devices, just when I tried to simulate on the browsers that I used in my PC.
Take a look:
PC looks like these: Image
Mobile... Image
Ah! The codes:
#media screen and (max-width: 888px) {
body{background: url(../img/bgm.jpg) fixed no-repeat; background-size: cover;}
}
Thanks
Give this a whirl, just add it in your /head/
<meta name="viewport" content="width=device-width, initial-scale=1.0">
credit: https://www.w3schools.com/css/css_rwd_viewport.asp
If this doesn't fix it, it could be your background-position size if you have a div with a background image try contain as opposed to cover on the mobile version, or just upload the image that has the appropriate size, for ex: if the header is 300px wide by 150px height just resize the image to that
Finally worked!
After a deep search, I found this: background: fixed no repeat not working on mobile
body:before {
content: "";
display: block;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -10;
background: url(photos/2452.jpg) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}

Header image placement on IOS

My header image on my website (dorinart.com) is perfectly positioned in all browsers including android mobile browsers but when I open it on IOS (iphone, ipad) it only shows the top right corner of the image (you can check if you open dorinart.com). How could I resolve this issue?
my css looks like this:
.header{
background: url('../img/banner5.jpg');
background-repeat: no-repeat;
position: fixed;
background-size: cover;
min-height: 730px;
position: relative;
}
Can you try this CSS? I think you want to center the image in the space available right? Please let me know if this works:
.header{
background-image: url('../img/banner5.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position-x: center;
min-height: 760px;
position: relative;
}
If you don't want it centered, then just remove the background-position-x property.
Hope this helps. Thanks.
Update: Attached screenshot from simulator:
I have had a similar issue recently and realised that it's due to background-size:cover with background-attachment:fixed.
In your website its like this:
background: url('../img/banner5.jpg') no-repeat fixed;
background-size: cover;
min-height: 760px;
position: relative;
Here the background-attachment:fixed is the problem.
I solved the issue by using a media query for iPhone and setting background-attachment property to scroll.
So what you can do is use this:
.header{
background-size: cover;
background-attachment: fixed;
#media (max-width: #iphone-screen) {
background-attachment: scroll;
}
}

White block in web page background on Ubuntu

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!

How can I resize an image so it fits the entire window?

I have an image for a website and I wish to resize it so it covers ANY given screen.
Note:
I don't want the scrollbars to appear.
I am trying to resemble something like the following website
http://frontrow-demo.squarespace.com/
The only solution I can think of was re-sizing the height and width but that makes the scroll bars appear. I am guessing its a CSS solution I am struggling to create.
Edit:
This is the code I tried, but its "Zooming" the pic to make it stretch across the screen. I would like it to resize it so the quality and the actual pic would show up.
#bg {
position: fixed;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
}
Just use some simple css
#theimg {
position : fixed; /*can also use absolute and the parent element can have relative*/
top : 0;
left : 0;
width : 100%;
height : 100%;
}
here is a demo fiddle
http://jsfiddle.net/rg3eK/
You want to use the CSS background property: http://css-tricks.com/perfect-full-page-background-image/
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;
}
Works in:
Safari 3+
Chrome Whatever+
IE 9+
Opera 10+ (Opera 9.5 supported background-size but not the keywords)
Firefox 3.6+ (Firefox 4 supports non-vendor prefixed version)
Anchor it to the sides and set the size to auto.
img#fullscreen {
height:auto;
width:100%;
left:0;
right:0;
top:0;
position:absolute;
}
Working fiddle.
This won't resize to the bottom (the one on the linked page also doesn't) but also doesn't mess the aspect of the image.
You may want to check photo-resize option.
Or you may try adding this:-
<img src="picture.jpg" width="100%" alt="">
ie, if you set only one dimension of an image, the other will end up being proportional to it.
or this:-
#image{
min-width:100%;
min-height:100%;
height:auto;
width:auto;
left:0;
right:0;
bottom:0;
top:0;}
Use background-size: cover in CSS on the HTML element
html {
background: url(http://i.imgur.com/tENv1w4.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
See this fiddle:
jsFiddle
For a better css.you must use this
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;
}

Background repeats and I am not sure why

I have a large image I would like as my background, but for some reason it repeats a little bit on my large screen. Is there a way I can just have the image size up or down according to screen size?
EDIT: So I have changed my HTML to look like this:
<body id="wrapper">
<div id="body">
<img src="/images/sky2.jpg" class="stretch" alt="" />
</div>
and my CSS to this:
#body {
width: 100%;
height: 100%;
position: absolute;
left: 0px;
top: 0px;
z-index: 0;
}
.stretch {
width:100%;
height:100%;
}
And the background won't show on preview. I have 3 other div elements that show but only to a white background =/.
move background-repeat: no-repeat; to the #body instead of #body img
You aren't actually showing any of your html here, just some embedded CSS and some (I assume linked?) CSS. You are loading the image as a background-image on the body element in that first bit of css, which is great. Because it's loaded as a background-image in CSS, and not and tag in HTML, your second bit of CSS (with the #body img selector) is not affecting it in any way.
What you actually have, in effect, is this:
#body {
position:fixed;
top:-50%;
left:-50%;
width:200%;
height:200%;
position:relative;
background-image: url(images/sky2.JPG);
}
Which is a very odd bit of code. But the only relevant part to your question is the background-image part. The answer has several parts. In CSS2: no, you cannot adjust the size of a background image. You can set it not to repeat (as others have shown) and you can set it's position:
body {
background-position: center left;
}
In CSS3 you can change the size, and you have several options (you are looking for cover, I think) but it only works for the latest browsers. The property is called background-size, but because it is still experimental, you have to declare it individually for each browser:
/* this is the default */
body {
-moz-background-size: auto;
-webkit-background-size: auto;
-o-background-size: auto;
background-size: auto;
}
/* this will size the image proportionally so that it is contained, but not cropped */
body {
-moz-background-size: contain;
-webkit-background-size: contain;
-o-background-size: contain;
background-size: contain;
}
/* this will size the image proportionally so that it fills all the area */
body {
-moz-background-size: cover;
-webkit-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
/* this will size the image as a percentage of the area */
.example #percent {
-moz-background-size: 50% 50%;
-webkit-background-size: 50% 50%;
-o-background-size: 50% 50%;
background-size: 50% 50%;
}
/* this will size the image to exact specifications */
.example #absolute {
-moz-background-size: 100px 25px;
-webkit-background-size: 100px 25px;
-o-background-size: 100px 25px;
background-size: 100px 25px;
}
#img.source-image {
width: 100%;
position: absolute;
top: 0;
left: 0;
}
Demo page:
http://css-tricks.com/examples/ImageToBackgroundImage/
Source:
http://css-tricks.com/how-to-resizeable-background-image/
I think it's worth to read that page :)
1) The CSS property background-repeat: no-repeat; should be on the body element itself, i.e. on the element you're specifying the background of.
2) In the CSS, you write #body... I guess you want to talk about the body element? Then you should just write body in the CSS. #body would be for an element declared as, say, <div id="body">.
3) Also, I'm unsure about #body img. #body img means “an img element inside the body”. Do you really have an img element inside the body? I mean, is your markup like this?
<body>
...
<img ... >
...
</body>
And do you really want to style that img element?
Anyway, the style that applies to the img element has nothing to do with the body's background.
<style type="text/css">
body {
background-image: url(images/sky2.JPG);
background-repeat: no-repeat;
}
</style>
You need to set it for the same element or class or whatever.
Also you could move the body css into your css.
Ok, I'm sorry there are some other things wrong, like #body {. I don't think you have an element with an id "body".
Not trying to RTFM, but maybe read some tutorials on CSS?
To scale the image, maybe have a look at: Stretch and scale a CSS image in the background - with CSS only