z-index does not work
Hi guys, I'm facing a problem related to
z-index. I have a table where the first column has a sticky position, and inside the cells of the first column, I'm using a tooltip component from flowbite-react. However, I'm not sure why the first tooltip in the first cell is placed below the second cell, even though I try to add a higher z-index for the cell. I'd appreciate any ideas to help me fix this problem.

10 Replies
It's difficult to tell what is causing this without having an isolated reproduction of the html and css. Tho, does the
z-[1] get converted to a valid class name? Square brackets are used for html attributes, so perhaps your index number does not get applied in the first placeIt's a tailwind custom class, so I'm quite sure it's applied. I even tried to use style inline and it still did not work
sticky position creates a new stacking context, and you have (presumably) applied the sticky class to each of the cells in the first column, possibly the subsequent column cells are stacking above the previous one.Here's a demo of a faulty parent stacking context – https://jsfiddle.net/Lbnwc3m4/
-# all about that topic by the lovely Josh Comeau https://www.joshwcomeau.com/css/stacking-contexts/
Edit fiddle - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
if i were you, i would do what used to be done way back when: add the tooltip html to the body, then trigger it on an hover
so, you have a global tooltip element
you can still have that element thingy too
but instead, you return a span that has an hover event
and when the element is hovered, then you show the global tooltip
or a div
use
display: contents on itSorry, I don't really understand what you mean. Can you give me an example?
the element you want to show is inside the
<body>
the tooltip one
then you can position absolute it to where you want it
the <tooltip> element you have should just have a div or span that has display: contents and an hover event
the hover is where you position the tooltip on the screenI see. Yeah, properly escaping the parent like this isn't possible. You either need to set a
z-index for each table-row, but always +1 the :hover one (experimental thought, https://jsfiddle.net/bmzc3ynh/) – or handle the tooltip outside of the cell, like epic mentioned – or look into anchor positioning, tho I am unsure if this is different.
It works for the last few ones because they overlap previous rows.yeah, it works because of a miracle