Overlapping page components can hide a menu even when its z-index is much larger than the header's. Debugging CSS z-index layering means finding the stacking context that controls the overlap, rather than repeatedly increasing the hidden element's number.

A stacking context keeps its descendants together in the page's stacking order. A positioned parent with a non-auto z-index creates one, so a menu inside it cannot outrank a higher sibling context. Properties such as transform, opacity below 1, and isolation: isolate can create the same boundary.

Chrome's Elements panel exposes the rules on both the hidden element and its ancestors. The important comparison is between contexts that share a parent, not between arbitrary descendants. A change saved in the stylesheet must survive a reload at the viewport, scroll position, and menu state where the failure occurred.

Steps to debug CSS z-index layering:

  1. Create a file named index.html in your text editor with a header and a menu inside a workspace.
    index.html
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>CSS stacking order</title>
      <style>
      </style>
    </head>
    <body>
      <header class="site-header">Site header</header>
      <main class="workspace">
        <nav class="menu">
          <strong>Project menu</strong>
          <p><a href="#reports">Open reports</a></p>
        </nav>
      </main>
      <p id="reports">Reports section</p>
    </body>
    </html>

    The small page reproduces a menu trapped below a sibling header. On an existing site, the corresponding elements are the obscured overlay, its containing component, and the layer covering it.

  2. Add these appearance rules inside the empty style element.
    body { margin: 24px; font: 18px/1.4 sans-serif; }
    .site-header { padding: 24px; background: #27344d; color: white; }
    .workspace { min-height: 180px; background: #e8eef8; }
    .menu { padding: 16px; background: #fff4cf; border: 2px solid #b56b00; }
  3. Append these positioning rules after the appearance rules inside style.
    .site-header { position: relative; z-index: 20; }
    .workspace { position: relative; z-index: 1; }
    .menu { position: absolute; top: -28px; left: 24px; z-index: 9999; }

    The negative top makes the menu overlap the header. The menu's 9999 belongs inside the workspace's stacking context.

  4. Save index.html as a plain-text HTML file.
  5. Open the saved index.html file in Chrome.

    The address begins with file:/// and ends with the file's location on your computer. No web server is needed.

  6. Activate Chrome's element picker with Ctrl+Shift+C on Windows or Linux, or Command+Option+C on macOS.

    The header covers the upper edge of the yellow menu and part of its title. The shortcut opens DevTools in inspection mode.

  7. Select the menu by clicking the yellow padding beside Open reports.

    The padding belongs to nav.menu; clicking the link text would select the child link instead.

  8. Select main.workspace in the Elements tree above nav.menu.

    Before moving to the parent, Styles shows that the menu already has position: absolute and z-index: 9999. Its parent is the next place to inspect.

  9. Select header.site-header in the Elements tree above main.workspace.

    The workspace has position: relative and z-index: 1, which creates a stacking context. The header is its sibling, so their stack levels can be compared directly.

  10. Compare the header's z-index: 20 in Styles with the workspace's z-index: 1.

    The header outranks the entire workspace, including its menu. Raising the menu's 9999 cannot change that comparison. On a nested page, the relevant pair is the two competing contexts under their nearest shared stacking context.

  11. Replace the workspace positioning rule in index.html with this rule in your text editor.
    .workspace { position: relative; z-index: 30; }

    This replaces .workspace { position: relative; z-index: 1; } and raises the context that competes with the header. If an existing site's context comes from an unnecessary transform or opacity rule, removing that trigger may be the smaller fix. A layer clipped by overflow: hidden needs its clipping rule addressed instead.

  12. Save the changed index.html file.

    Editing the actual source keeps the change after a reload; an unsaved edit in Styles does not.

  13. Reload index.html with Chrome's Reload button.
  14. Confirm that the menu's full top border and Project menu title appear above the header after the reload.

    The menu now crosses the header while its own z-index remains 9999. On an existing site, the same overlap must also work in the original menu state and viewport after the stylesheet change is saved.

Share this guide