title: How to control z-index of a child of a sticky element
body: <p>I have two <code>container</code> elements which have <code>position: sticky</code> and a <code>z-index: 1</code>.</p>
  
  <p>One of those elements has a child node with <code>position: absolute</code>.</p>
  
  <p>I would like the child node to be visually on top of both <code>container</code> elements.</p>
  
  <p>This is the html structure I must keep and what I have tried:</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>.square {
    height: 100px;
    width: 100px;
    position: absolute;
    background-color: red;
    z-index: 10; /* this doesn't work */
  }
  
  .container {
    height: 40px;
    width: 200px;
    position: sticky;
    background-color: blue;
    margin-top: 1rem;
    margin-bottom: 1rem;
    z-index: 1;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;body&gt;
      &lt;div class="container"&gt;
        &lt;div class="square"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="container"&gt;&lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is how it currently looks:</p>
  
  <p><a href="https://i.stack.imgur.com/H1WVV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/H1WVV.png" alt="enter image description here"></a></p>
  
  <p>This is how I would like it to look:</p>
  
  <p><a href="https://i.stack.imgur.com/Ybago.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ybago.png" alt="enter image description here"></a></p>
  
  <p>But I would like to keep the <code>html</code> structure and the <code>sticky</code> alignment of the <code>container</code> elements.</p>