cssgoogle-chromewebkitfixedbackground-attachment

Chrome issue with background-attachment fixed and position fixed elements


I've had this issue for a while and it seems to be a Chrome redraw bug that hasn't been fixed. So I'm looking for any stop-gap fixes.

The main issue is that when an element on the page has a background image that uses:

background-attachment: fixed;

If another element is fixed and has a child video element it causes the element with the background image to disappear.

Now it works fine in Safari (and Firefox and IE) so it's not exactly a webkit issue. I've applied several properties that have been suggested to no avail.

-webkit-backface-visibility: hidden;
-webkit-transform: translate3d(0, 0, 0);

Initial Demo

Currently my solution is just to target the elements with a fixed bg image via a media query and just turn off the fixed background property.

@media screen and (-webkit-min-device-pixel-ratio:0) {
background-attachment: scroll;
}

Any ideas?

Update

Working Demo thanks to Daniel.

Update 2

Better demo!

Shoutout to somesayinice and FourKitchens blog post


Solution

  • Found this solution on: https://fourword.fourkitchens.com/article/fix-scrolling-performance-css-will-change-property

    Seems to me to be a clever way to use :before pseudo element. Limit the width for fixed width elements but works great for full width pages. Essentially comes out to look like this:

    .background_fill {
      overflow: hidden;
      position: relative;
        color: red;
    }
    .background_fill:before {
      background-color: white;
      background: url('http://www.lausanneworldpulse.com/pdfs/brierley_map_0507.jpg') no-repeat center center;
      background-size: cover;
      z-index: -3;
      content: " ";
      position: fixed;
      will-change: transform;
      width: 100%;
      height: 100%;
    }
    <div class="background_fill">
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
      <div>this is on a background / this is on a background / this is on a background / this is on a background / this is on a background / this is on a background</div>
    </div>

    Works great for me as a way of getting around this very annoying bug.