title: CLS (Cummulative Layout Shift ) in sticky navigations with position: fixed
body: <p>With the new Web Vitals incoming I have a problem with my sticky navigations/menus. In fact most pages will have :-(</p>
  <p>The problem is that I use an approach like bootstrap affix to make the menu sticky when it would leave the viewport. But every time the menu leaves the viewport (and enters it as well) and the position is set from <code>relative/static/absolute</code> to <code>fixed</code> it increases CLS (Cumulative Layout Shift). I realize that changing the position to <code>fixed</code> will result in a layout shift because the element is removed from the layer and all following elements will be shifted to the top.</p>
  <p>BUT: That's why I came up with some solutions and the best I think is that I use a wrapper with a specific height around the menu. So when the position of the menu changes to fixed the wrapper still exists and does not change in position or height, which means that no following elements has to shift. But the CLS is still counting up. And I do not know what to do to make my menus sticky without affecting the CLS which is important. Btw I cannot use position: sticky because there is not enough browser support. Because if my researches are correct <code>position: sticky</code> works without negatively affecting the CLS, my solution does not although the user **does not see any difference at all **....</p>
  <p>Here comes some <strong>pseudo code</strong> to be more visual:</p>
  <pre><code>...
  &lt;body&gt;
     &lt;h1&gt;
        Headline
     &lt;/h1&gt;
  
     &lt;p&gt;
        Here is some elements an stuff
     &lt;/p&gt;
  
     &lt;div class=&quot;menu-wrapper&quot;&gt;
        &lt;div class=&quot;menu&quot;&gt;
           &lt;ul&gt;...........&lt;/ul&gt;
        &lt;/div&gt;
     &lt;/div&gt;
  
     &lt;p&gt;
        More elements and stuff. Nothing shifting because the wrapper always has the same height.
     &lt;/p&gt;
  ...
  &lt;/body&gt;
  ...
  </code></pre>
  <pre><code>.menu-wrapper {
     height: 60px;
     width: 100%;
  }
  
  .menu {
     height: 60px;
     width: 100%;
     position: static;
  }
  
  .menu.affix {
     position: fixed;
     top: 0;
  }
  </code></pre>
  <p>Any ideas? Thank you very much!</p>