Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed background image with ios7

I have a project that I am using the fixed background image. It works great on everything except ios7. On the ipad the background image is zoomed in and blurry. Here is the CSS code I am using -

.header {   display: table;   height: 100%;   width: 100%;   position: relative;   color: #fff;   background: url(../images/boston2.jpg) no-repeat center center fixed;    -webkit-background-size: cover;   -moz-background-size: cover;   -o-background-size: cover;   background-size: cover;   } 

here is a link to the live page - www.wdeanmedical.com

What am I missing?

like image 406
user2560895 Avatar asked Dec 07 '13 16:12

user2560895


People also ask

How do you keep the background of a picture fixed?

To keep your background fixed, scroll, or local in CSS, we have to use the background-attachment property. Background-attachment: This property is used in CSS to set a background image as fixed or scroll. The default value of this property is scroll.


2 Answers

Using background-attachment: fixed with background-size: cover causes issues on most mobile browsers (as you've seen). You can try using background-attachment: scroll. This won't give your desired effect, but you'll see the images at least. You could use a media-query or two to limit it to devices that are tablets or phones by using @media screen and (max-device-width: 1024px){}

OR

You can use background-position: scroll and include some javascript that will keep the image at the scrolled position (keeping it at the top of the window): DEMO

like image 53
brouxhaha Avatar answered Nov 15 '22 15:11

brouxhaha


Know this is an old thread, but wanted to provide an updated solution that builds on the solution from @Cruz-Nunez

Relying on viewport size is liable to fail. For example, relying on a 767px viewport won't work on iPads, and increasing the size negates the benefit of this approach.

Instead, you can check if the device has hover capabilities, and if it doesn't, override like this:

@media (hover: none) {    .homeHero {        background-attachment: initial;    } } 

You can also check if the device has a coarse pointer (e.g. a finger) instead of a fine one (e.g. a mouse):

@media (pointer: coarse) { ... } 
like image 38
Tim Avatar answered Nov 15 '22 13:11

Tim