What I'm trying to do is placing the <button>
element on top of the <div>
element and, at the same time, place the <nav>
behind the <div>
. In other words, anything but the <button>
should be visible.
Demo: https://play.tailwindcss.com/DW91IdO9dL
- A sticky
<nav>
element withposition: sticky
- The
<nav>
has a<button>
child withposition: relative; z-index: 30
- A
<div>
element withposition: fixed; z-index: 20
Of course, this isn't working, <button>
isn't visible at all, despite the greater z-index
. I guess because the <nav>
crate a new stacking context. Setting a z-index: 30 on the <nav>
itself would show the <button>
, but also other <nav>
elements and its background color:
This is the HTML structure, but I can change as I wish (place the <div>
before/after):
<nav style="position: sticky">
<button style="position: relative; z-index: 30"></button>
</nav>
<div style="position: fixed: z-index: 20"></div>