Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does a background-attachment of fixed work in iOS5?

Tags:

css

ios

Does this work in > iOS 5?

.element {
    background: url(images/myImage.jpg) 50% 0 no-repeat fixed;
}

I thought that it should, but so far it isn't.

like image 426
Dylan Avatar asked Mar 19 '12 22:03

Dylan


People also ask

What does background-attachment fixed do?

The background-attachment CSS property sets whether a background image's position is fixed within the viewport, or scrolls with its containing block.

How to make a fixed background image using CSS?

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.

How many values does the background-attachment property can take?

The background-attachment property in CSS specifies how to move the background relative to the viewport. There are three values: scroll , fixed , and local .


2 Answers

You can potentially get around this using a separate element and position: fixed which does work!

HTML:

<div id="Background"></div>

<div id="Content"></div>

CSS:

#Background {
    background: #000 url("img/Background.jpg") no-repeat 50% 0;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1
}
like image 150
shshaw Avatar answered Oct 17 '22 00:10

shshaw


According to this background-attachment support matrix, no.

Another post suggests that coming up with a workaround for mobile devices is not worth it:

...both Android and iPhone block timers or render during scroll, so the effect is that divs move with the scrolled page and only after, eventually, divs come back in the expected position. This is against position fixed idea

like image 39
Oleg Avatar answered Oct 17 '22 00:10

Oleg