Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE 6 & IE 7 Z-Index Problem

Tags:

http://madisonlane.businesscatalyst.com

I'm trying to get the div#sign-post to sit above the div#bottom. This works fine in all browsers except IE6 & IE7. Can anyone see what the problem is here?

Also IE6 is displaying an additional 198px to the top of div#bottom.

like image 427
mattt Avatar asked Mar 23 '09 04:03

mattt


People also ask

Does Internet Explorer 6 still work?

Internet Explorer 6 was the last version to be called Microsoft Internet Explorer. The software was rebranded as Windows Internet Explorer starting in 2006 with the release of Internet Explorer 7. Internet Explorer 6 is no longer supported, and is not available for download from Microsoft.

Can I install IE6 on Windows 10?

It is not possible to run any other version of IE except IE11 on Windows 10. If you literally need IE6 run it within a virtual machine, Microsoft provides free virtual machines, for exactly this purpose.

Can I download Internet Explorer 6?

Thankfully, the Internet Archive, which is dedicated to preserving internet history, has a copy of IE6 with Service Pack 1 available to download. It's available as either a torrent download or ZIP file, weighing in around 78MB.

What is IE Class 6?

Answer: Internet Explorer is a series of graphical web browsers developed by Microsoft and included in the Microsoft Windows line of operating systems, starting in 1995. It was first released as part of the add-on package Plus! for Windows 95 that year.


1 Answers

Most of the answers here are wrong; some work, but not for the reason they state. Here is some explanation.

This is how z-index should work according to the spec:

  • you can give a z-index value to any element; if you don't, it defaults to auto
  • positioned elements (that is, elements with a position attribute different from the default static) with a z-index different from auto create a new stacking context. Stacking contexts are the "units" of overlapping; one stacking context is either completely above the another (that is, every element of the first is above any element of the second) or completely below it.
  • inside the same stacking context, the stack level of the elements is compared. Elements with an explicit z-index value have that value as a stack level, other elements inherit from their parents. The element with the higher stack level is displayed on top. When two elements have the same stack level, generally the one which is later in the DOM tree is painted on top. (More complicated rules apply if they have a different position attribute.)

In other words, when two elements have z-index set, in order to decide which will show on top, you need to check if they have any positioned parents which also have z-index set. If they don't, or the parents are common, the one with the higher z-index wins. If they do, you need to compare the parents, and the z-index of the children is irrelevant.

So the z-index decides how the element is placed compared to other children of its "stacking parent" (the closest ancestor with a z-index set and a position of relative, absolute or fixed), but it doesn't matter when comparing to other elements; it is the stacking parent's z-index (or possibly the z-index of the stacking parent's stacking parent, et cetera) which counts. In a typical document where you use z-index only on a few elements like dropdown menus and popups, none of which contains the other, the stacking parent of all the elements which have a z-index is the whole document, and you can usually get away with thinking of the z-index as a global, document-level ordering.

The fundamental difference with IE6/7 is that positioned elements start new stacking contexts, whether they have z-index set or not. Since the elements which you would instinctively assign z-index values to are typically absolutely positioned and have a relatively positioned parent or close ancestor, this will mean that your z-index-ed elements won't be compared at all, instead their positioned ancestors will - and since those have no z-index set, document order will prevail.

As a workaround, you need to find out which ancestors are actually compared, and assign some z-index to them to restore the order you want (which will usually be reverse document order). Usually this is done by javascript - for a dropdown menu, you can walk through the menu containers or parent menu items, and assign them a z-index of 1000, 999, 998 and so on. Another method: when a popup or dropdown menu becomes visible, find all its relatively positioned ancestors, and give them an on-top class which has a very high z-index; when it becomes invisible again, remove the classes.

like image 51
Tgr Avatar answered Sep 18 '22 15:09

Tgr