title: Navigation bar : position Absolute and Sticky
body: <p>I'm trying to make a navigation bar <strong>that overlap</strong> my header and stick to the top of the window on scroll.<br>
  It will start at <code>top: 45px</code> and stick at <code>top: 0</code> on scroll.</p>
  
  <p>My first approach was to set it at <code>position: fixed; top: 45px</code> and change the value with JS on a <code>scroll</code> event. But Firefox gave me the warning about "<em>asynchronous panning</em>" discussed on <a href="https://stackoverflow.com/questions/37098306/this-site-appears-to-use-a-scroll-linked-positioning-effect-this-may-not-work">this post</a>.</p>
  
  <p>I have been able to do it with a bit of CSS trickery, but I am wondering if there is a <strong>simpler CSS way or a valid JS approach</strong> to do this (not throwing a warning).</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>body {
    position: relative;
    height: 100%;
    width: 100%;
    background-color: grey;
    overflow-x: hidden;
    margin: 0;
  }
  
  .container {
    position: absolute;
    top: 0;
    left: -1px;
    width: 1px;
    bottom: 0;
    padding-top: 45px;
    overflow: visible;
  }
  
  nav {
    position: sticky;
    top: 0;
    transform: translateX(-50%);
    margin-left: 50vw;
    width: 300px;
    height: 70px;
    background-color: red;
  }
  
  header {
    height: 50vh;
    background-color: blue;
  }
  
  main {
    height: 200vh;
    width: 100%;
    background-color: green;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="container"&gt;
    &lt;nav&gt;&lt;/nav&gt;
  &lt;/div&gt;
  &lt;header&gt;
  &lt;/header&gt;
  &lt;main&gt;
  &lt;/main&gt;</code></pre>
  </div>
  </div>
  </p>