95

I'm trying to get fixed-background-image divs working on iOS for a school project. I've been using

background-attachment: fixed;

But this is leading to weird sizing and no scrolling effects in mobile safari. Here is the site that I'm working with; the method I'm currently using for the quote div image backgrounds works well on desktops but fails completely on iOS.

Somehow, http://www.everyonedeservesgreatdesign.com got this working. I'm having difficulty following the code because they're using a squarespace template of some kind, but it looks like they're putting images into a position:fixed div that is somehow being clipped by its position:relative parent div. I was under the impression that it wasn't possible to clip position:fixed divs with anything other than the viewport, so I'm very curious as to what's going on here.

Any ideas on how to implement this method for fixed image div backgrounds in my site?

2
  • Hey this is not related to your question but the links in the bottom break your layout in mobile. Try putting some overflow-x hidden to the body and the mail div so it doesn't scroll horizontally. May 2, 2014 at 3:44
  • This is marked as a duplicate yet no duplicate question has been identified and this is the question with the most upvotes. SMH.
    – vhs
    Oct 4, 2017 at 17:44

2 Answers 2

128
+100

It has been asked in the past, apparently it costs a lot to mobile browsers, so it's been disabled.

Check this comment by @PaulIrish:

Fixed-backgrounds have huge repaint cost and decimate scrolling performance, which is, I believe, why it was disabled.

you can see workarounds to this in this posts:

Fixed background image with ios7

Fixed body background scrolls with the page on iOS7

5
  • 1
    I'm curious about the specific technique being used by everyonedeservesgreatdesign.com, which seems to be unique in that it uses images with position:fixed instead of a javascript-based workaround.
    – QRohlf
    May 2, 2014 at 16:16
  • 2
    It is not just css, look at #parallax-images div the image-container has inline css. This is handled in static.squarespace.com/static/ta/515c7b5ae4b0875140c3d94a/2476/… May 2, 2014 at 16:36
  • 1
    Ah, thank you. I was really wondering how they managed to pull off the effect without js; looks like the answer is that they did not.
    – QRohlf
    May 2, 2014 at 18:50
  • 17
    This is interesting. I don't know if this was true five years ago, but not only is this not disabled on android, but profiling with and without a fixed background I only see a 1% framerate difference. iOS should remove this limitation...
    – Nick Bilyk
    Feb 28, 2020 at 17:23
  • The comment is not a defined conclusion but more of an assumption. We need more data to be ensured about that. May 24, 2021 at 3:46
2

It looks to me like the background images aren't actually background images...the site has the background images and the quotes in sibling divs with the children of the div containing the images having been assigned position: fixed; The quotes div is also given a transparent background.

wrapper div{
   image wrapper div{
       div for individual image{ <--- Fixed position
          image <--- relative position
       }
   }
   quote wrapper div{
       div for individual quote{
          quote
       }
   }
 }

Not the answer you're looking for? Browse other questions tagged or ask your own question.