IE7/8 z-indexing
filed in JavaScript, jQuery on Aug.25, 2009
It seems IE7 and IE8 give each element within a document an increasing z-index automatically, based on the position of where the element shows up in the flow of the HTML. This is a problem if you are using something like a drop down menu and it needs to cover the contents of the elements below it. While this will work perfectly in Firefox and Chrome (unsure about other browsers), in IE 7 and 8 it simply fails to allow a floating div that appears first within the HTML to show above elements that are relatively placed that appear further down the markup.
If you are using jQuery, the fix is rather simple - the following code reverses the natural z-indexing that is generated and assures that elements higher in the page will actually have a higher z-index then elements appearing lower:
-
$(document).ready(function()
-
{
-
$(function()
-
{
-
var zIndexNumber = 1000;
-
$(’div’).each(function()
-
{
-
$(this).css(’zIndex’, zIndexNumber);
-
zIndexNumber -= 10;
-
});
-
});
-
});
Additionally here is a fix using MooTools 1.2:
-
if (Browser.Engine.trident)
-
{
-
var zIndexNumber = 1000;
-
$$(’div’).each(function(el,i)
-
{
-
el.setStyle(’z-index’,zIndexNumber);
-
zIndexNumber -= 10;
-
});
-
};
Via: http://www.vancelucas.com/blog/fixing-ie7-z-index-issues-with-jquery/
Leave a Reply