title: How do I fix background image to viewport of <div /> that using transfrom?
body: <p>I am working on flipping card pages that have a single image as a card background and they should look like the image is splited. And card flipping animation is made with <code>transition</code>, <code>transform: rotateX</code>, <code>transform-style: preserve-3d;</code></p>
  <p>After reading this question, <a href="https://stackoverflow.com/questions/43552370/fixed-position-background-image-in-firefox-doesnt-work-with-transformed-element">Fixed position background image in Firefox doesn't work with the transformed element. Is this a FF bug?</a>. I know it's impossible to attach background fixed with the viewport using only vanilla CSS and HTML in firefox and some browser because the element using <code>transform</code> change <code>background-attachment: fixed</code> into a  <code>scroll</code>.</p>
  <p>I know it could be an answer to separate a single image into multiple images, but it needs a lot of HTTP calls in real service.</p>
  <p>So I want to make a javascript code that fixes the standard condition of the background image. Is there an way to fix the background image regardless of the transform object?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.frame {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 400px;
    height: 400px;
    margin-top: -200px;
    margin-left: -200px;
    border-radius: 2px;
    box-shadow: 4px 8px 16px 0 rgba(0, 0, 0, 0.1);
    overflow: hidden;
    background: #333;
  }
  
  .wrapper {
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: space-evenly;
    height: 100%;
  }
  
  .card,
  .wrap {
    position: relative;
    width: 300px;
    height: 150px;
    border-radius: 12px;
    perspective: 350px;
  }
  
  .wrap {
    transition: 1.5s;
    transform-style: preserve-3d;
  }
  
  .card:hover .wrap {
    transform: rotateX(180deg);
  }
  .card:hover .wrap .front {
    transition: opacity;
    transition-delay: 0.4s;
    transition-duration: 0.25s;
    transition-timing-function: ease-in-out;
    opacity: 0;
  }
  
  .back,
  .front {
    position: absolute;
    width: 300px;
    height: 150px;
    border-radius: 12px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transform-origin: 50% 0;
    text-align: center;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    transition: opacity;
    transition-duration: 0.5s;
    transition-timing-function: ease-in-out;
    opacity: 1;
  }
  
  .front {
    background-image: url(https://wallpapercave.com/wp/wp5211914.jpg);
    background-attachment: fixed;
    background-position: top center;
    z-index: 1;
  }
  
  .back {
    transform: rotateX(180deg) translate(-50%, -50%);
  }
  
  .text-wrapper {
    color: #f2f2f2;
    font-size: 20px;
    text-align: center;
    height: 100%;
    font-family: Arial, Helvetica, sans-serif;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
    &lt;div class="frame"&gt;
      &lt;div class="wrapper"&gt;
        &lt;div class="card"&gt;
          &lt;div class="wrap"&gt;
            &lt;div class="front text-wrapper"&gt;
            &lt;/div&gt;
            &lt;div class="back text-wrapper"&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="card"&gt;
          &lt;div class="wrap"&gt;
            &lt;div class="front"&gt;
            &lt;/div&gt;
            &lt;div class="back"&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  <p><a href="https://codepen.io/dodok8/pen/JjEzeJO" rel="nofollow noreferrer">Same code on codepen</a></p>
  <p>If you want to see the result that I want, run the code in chrome, because it doesn't follow the spec that change <code>background-attachment: fixed</code> into a <code>scroll</code>.</p>
  <p>It's the result I want.(Run in Chrome)</p>
  <p><a href="https://i.stack.imgur.com/VHfYv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VHfYv.png" alt="Chrome Result" /></a></p>
  <p>Firefox Result.</p>
  <p><a href="https://i.stack.imgur.com/vZfms.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vZfms.png" alt="Firefox Result" /></a></p>