Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS z-index issue when inside of table cell

I have a calendar/table that when you hover over each day we have a small popup that is absolutely position below each cell.

To make this work I have added a <div style="relative" /> inside each cell. Works fine in FF although when you hover over it in IE the z-index is being ignored.

enter image description here

I have tried all of the hacks I can think of to get it to work in IE 7 + 8.

like image 629
John Magnolia Avatar asked Apr 30 '12 14:04

John Magnolia


People also ask

Why is Z Index not working CSS?

You set z-index on a static element By default, every element has a position of static. z-index only works on positioned elements (relative, absolute, fixed, sticky) so if you set a z-index on an element with a static position, it won't work.

How do I fix Z index in CSS?

To sum up, most issues with z-index can be solved by following these two guidelines: Check that the elements have their position set and z-index numbers in the correct order. Make sure that you don't have parent elements limiting the z-index level of their children.

Does Z Index work in table?

And it will, as it is in same stacking context. However, as soon as you give a z-index value to the div. bottom , it creates a new stacking context which confines all of its child elements to a particular place in the stacking order. This causes it not to appear in front of the tabs irrespective of the z-index of tabs.

Does Z Index work with position relative?

Note: Z index only works on positioned elements ( position:absolute , position:relative , or position:fixed ).


1 Answers

No need for all the individual z-indexes on the .wrapper div's inside the td elements (they can all be set to 1 I believe), and set these properties:

/* add these two to your selector */
#calendar tbody td {
  position: relative;
  z-index: 1;
}

/* create this new selector */
#calendar tbody td:hover {
  z-index: 2;
}

Using firebug and IE's developer tools, it appeared to me that it was working in Firefox and IE7 and 8.

like image 130
ScottS Avatar answered Sep 22 '22 03:09

ScottS