Click to See Complete Forum and Search --> : [RESOLVED] z-index IE6 bug - URGENT!!!!


Phill Pafford
01-28-2009, 01:35 PM
Hello All,

I have found that this IE6 z-index (http://verens.com/archives/2005/07/15/ie-z-index-bug/) bug is occurring in my code and wanted to know if there is a work around.

I'm working on a list styled navigation (http://www.cssplay.co.uk/menus/simple_vertical.html) (This is an example but very close to what I'm using) but some of the drop down menus display under other elements on the page.

The work is divided up among developers so there are other CSS pages as well which I have no control over. we do not use iframes to display the pages.

Maybe a JavaScript solution?

Help anyone !!!!!!

MorganA
01-28-2009, 03:36 PM
How many items have you assigned a z-index to? I ran into this with IE-6 one time - I believe it resolved itself when I made sure to assign z-index: 1 to the menu and z-index: -1 to nearly everything else.

talldean
01-28-2009, 03:52 PM
Hello All,

I have found that this IE6 z-index (http://verens.com/archives/2005/07/15/ie-z-index-bug/) bug is occurring in my code and wanted to know if there is a work around.

I'm working on a list styled navigation (http://www.cssplay.co.uk/menus/simple_vertical.html) (This is an example but very close to what I'm using) but some of the drop down menus display under other elements on the page.

The work is divided up among developers so there are other CSS pages as well which I have no control over. we do not use iframes to display the pages.

Maybe a JavaScript solution?

Help anyone !!!!!!

You'll need to display an iframe under the popup regions of the list. It's the only fix I know of to stop select-tag input boxes from appearing above the text. Let me dig out some example code.

talldean
01-28-2009, 03:55 PM
Here's some example Javascript. To make a popup work, it uses a piece of HTML and CSS as well, but it sounds like the Z-index is your only problem. The important piece here is "ie6HackMouseOver(o)" and the matching MouseOut.

/*
* This javscript applies onmouseover and onmouseout events to the top menu.
* 2009, Dean J, talldean at gmail dotters com
*/

/* This is the main function, that does the bulk of the work. */
function addMenuEvents() {
if (document.all && document.getElementById) {
navRoot = document.getElementById("topMenuJS");
// Cycle through all of the top level menus.
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {

// Whenever they mouse over a menu, open the submenu by changing the CSS class.
node.onmouseover=function() {
// If they were already over the menu, do not update this.
if (this.className.indexOf(' over') == -1) {
this.className+=' over';
this.childNodes[0].className+=' over';
ie6HackMouseOver(this);
}
}

// Whenever they mouse out of a menu, revert the change to the CSS class.
node.onmouseout=function() {
// Get the location of the mouse when this event was triggered.
mouseX = event.clientX; // + document.body.scrollLeft;
mouseY = event.clientY; // + document.body.scrollTop;
// Commenting this out for IE6; not necessary. Needs to be retested for IE7/FF3.

// Get the rectangle they supposedly left.
ul = this.childNodes[3];
ulRectangle = ul.getBoundingClientRect();

// Confirm the user left the rectangle before hiding this element.
// Documentation for this technique is at http://tinyurl.com/97cw39
if (mouseX - 1 < ulRectangle.left ||
mouseX + 1 > ulRectangle.right ||
mouseY - 1 < ulRectangle.top ||
mouseY + 1 > ulRectangle.bottom) {

this.className=this.className.replace(' over','');
this.childNodes[0].className=this.childNodes[0].className.replace(' over','');
ie6HackMouseOut(this);

}
}
}
}
}

// Finally, if we are in IE6, attempt to fix image flicker by turning on the cache.
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) && new Number(RegExp.$1) <= 6) {
try {
document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}
}
};


/* Microsoft browsers before IE 7 require an IFRAME displayed below the popup menus. If this is not done, SELECT tags are rendered
on top of the menu, which is a bug. */
function ie6HackMouseOver(o) {
// Check for IE6 or earlier.
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) && new Number(RegExp.$1) <= 6) {

ul=o.childNodes[3];
li=ul.childNodes[0];
width=li.offsetWidth;
height=li.offsetHeight * ul.childNodes.length;

iframe=o.childNodes[2];
iframe.style.display="inline";
iframe.style.height=height;
iframe.style.width=width + 1;

iframe.style.top=o.offsetHeight - 2;
iframe.style.left=-1;
}
};
function ie6HackMouseOut(o) {
// Check for IE6 or earlier.
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent) && new Number(RegExp.$1) <= 6) {
iframe=o.childNodes[2];
iframe.style.display="none";
}
};

talldean
01-28-2009, 04:06 PM
Forgot one bit. In the HTML, it's:


<div id="topMenuCSS">
<ul id="topMenuJS">
<li>
<a href="#">Label</a>
<iframe></iframe>
<ul>
<li>
<a href="google.com">Subnav Option 1</a>
</li>
<li>
<a href="google.com">Subnav Option 2</a>
</li>
</ul>
</li>
</ul>
</div>


And in the CSS:

#topMenuCSS iframe {
display:none;
width:1px;
height:1px;
position:absolute;
border:none;
margin:0;
}

fireblade
01-28-2009, 04:22 PM
You told
but some of the drop down menus display under other elements on the page.
Do you have any flash element in your page. If you have Flash element, this will occur. If it is so, use the wmode to transparent in parameter of flash object. Then it will be solved.

Phill Pafford
01-29-2009, 10:35 AM
Thanks all for the replies.

Sorry fireblade no flash is used, but thanks for the tip.

talldean I have also tried you method with no luck, any other thoughts suggestions?

BTW: how/when do I call the javascript?

MorganA
01-29-2009, 12:59 PM
I applied the z-index to the javascripts containing div. :confused:

Phill Pafford
01-29-2009, 01:09 PM
Thanks MorganA but the question was to talldean. Need to know when and what JavaScript function to call

Phill Pafford
01-30-2009, 11:42 AM
I have also tried to add a z-index 0r -1 to all the position tags in all the CSS external sheet, but no luck as well :-(

Any other thoughts?

Phill Pafford
01-30-2009, 12:07 PM
This seems to be the problem (http://20.targetprocess.com/2006/07/ie6-select-and-z-index-problem.html) but the fix is not working correctly, maybe Im implementing it wrong.

Phill Pafford
01-30-2009, 03:19 PM
Something new, but still not working, any help on this?

I'm trying to use Tanny O'Haley's solution (http://tanny.ica.com/ica/tko/tkoblog.nsf/dx/select-tag-overlap-in-ie-part-iii), but I think it's the javascirpt thats not working with my HTML and CSS.

It displays once when I refresh the page and leaves an outline of where the menu was (Kinda), but after that it displays behind the select menu on the page.

Example Navigation based from STU's nav (http://www.cssplay.co.uk/menus/simple_vertical.html)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<div class="cssnav">
<ul class="nav" id="nav">
<li>
<a href="#" target="_top">Menu 1
<!--[if IE 7]><!--></a>
<!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="drop">
<li>
<a href="#" target="_top">Link 1</a>
</li>
<li>
<a href="#" target="_top">Link 2</a>
</li>
<li>
<a href="#" target="_top">Link 3</a>
</li>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li>
<a href="#NO_HREF" class="no_href_cursor">Menu 2
<!--[if IE 7]><!--></a>
<!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="drop">
<li>
<a href="#NO_HREF" class="no_href_cursor">Sub-Menu 1
<!--[if IE 7]><!--></a>
<!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="drop">
<li>
<a href="#" target="_top">Link 1</a>
</li>
<li>
<a href="#" target="_top">Link 2</a>
</li>
<li>
<a href="#" target="_top">Link 3</a>
</li>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<li>
<a href="#NO_HREF" class="no_href_cursor">Sub-Menu 2
<!--[if IE 7]><!--></a>
<!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="drop">
<li>
<a href="#" target="_top">Link 1</a>
</li>
<li>
<a href="#" target="_top">Link 2</a>
</li>
<li>
<a href="#" target="_top">Link 3</a>
</li>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
</ul>
</div>
</body>
</html>


The CSS

/* Cursor for no href links */
.no_href_cursor {
cursor: text;
}

/* Overarching Menu
-----------------------------------*/
.cssnav {
position:relative;
z-index:9999;
font-size:12px;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-weight:bold;
text-align:center;
height: 25px;
overflow: visable;
width: 100%;
background:#467aa7;
border: 1px solid #fff;
}
.cssnav ul {
padding:0;
margin:0;
list-style-type:none;
}
.cssnav ul ul {
width:150px;
text-align:left;
}
/* Main list
-----------------------------------*/
.cssnav li {
float:left;
width:150px; /* This controls the width of the topnav was 106 or 150 */
position:relative;
_top: 1px; /* IE6 will read this only */
background:none; /* Added to override style */
padding:0px; /* Added to override style */
}
/* First Level
-----------------------------------*/
/* Links */
.cssnav a, .cssnav a:visited {
display:block;
text-decoration:none;
color:#fefefe;
border-bottom: 1px solid #fff;
border-left: 1px solid #fff;
background:#467aa7;
line-height:25px;
}
/* Added to fix div span for IE6 */
.cssnav li li a {
border-bottom: 1px solid #fff;
border-top: 1px solid #fff;
_top: 0px; /* IE6 will read this only */
text-decoration:none;
}
/* Links on hover */
.cssnav a:hover, .cssnav ul ul a:hover{
color:#fff;
background:#80b0da;
text-decoration:none;
}
.cssnav :hover > a, .cssnav ul ul :hover > a {
color:#fff;
background:#80b0da;
text-decoration:none;
}
/* Second Level
-----------------------------------*/
/* Links */
.cssnav ul ul a, .cssnav ul ul a:visited {
background:#578bb8;
line-height:1em;
padding:5px 10px;
width:128px;
border-width: 0px 2px 1px 0px;
text-decoration:none;
}
/* Links on hover */
.cssnav ul ul a:hover {
background:#80b0da;
text-decoration:none;
}
/* Visibility */
.cssnav ul li:hover ul, .cssnav ul a:hover ul{
visibility:visible;
text-decoration:none;
}
/* Third Level
-----------------------------------*/
/* Links */
.cssnav ul ul ul a, .cssnav ul ul ul a:visited {
background:#578bb8;
text-decoration:none;
}
/* Links on hover */
.cssnav ul ul ul a:hover {
background:#80b0da;
text-decoration:none;
}
/* Positioning */
.cssnav ul ul ul{
left:149px;
*left:148px; /* IE Only */
top:-1px;
*border: 1px solid #fff; /* IE Only */
}
.cssnav ul ul ul.left {
left:-149px;
*left:-148px; /* IE Only */
}
/* Visibility */
.cssnav ul :hover ul ul{
visibility:hidden;
}

.cssnav ul :hover ul :hover ul{
visibility:visible;
}

/* Fourth Level
-----------------------------------*/
/* Links */
.cssnav ul ul ul ul a, .cssnav ul ul ul ul a:visited {
background:#578bb8;
text-decoration:none;
}
/* Links on hover */
.cssnav ul ul ul ul a:hover {
background:#80b0da;
text-decoration:none;
}
/* Positioning */
.cssnav ul ul ul ul{
left:149px;
*left:148px; /* IE Only */
top:-1px;
*border: 1px solid #fff; /* IE Only */
}
.cssnav ul ul ul ul.left {
left:-149px;
*left:-148px; /* IE Only */
}
/* Visibility */
.cssnav ul :hover ul :hover ul ul {
visibility:hidden;
}

.cssnav ul :hover ul :hover ul :hover ul{
visibility:visible;
}

/* Fifth Level
-----------------------------------*/
/* Links */
.cssnav ul ul ul ul ul a, .cssnav ul ul ul ul ul a:visited {
background:#578bb8;
text-decoration:none;
}
/* Links on hover */
.cssnav ul ul ul ul ul a:hover {
background:#80b0da;
text-decoration:none;
}
/* Positioning */
.cssnav ul ul ul ul ul{
left:149px;
*left:148px; /* IE Only */
top:-1px;
*border: 1px solid #fff; /* IE Only */
}
.cssnav ul ul ul ul ul.left {
left:-149px;
*left:-148px; /* IE Only */
}
/* Visibility */
.cssnav ul :hover ul :hover ul :hover ul ul {
visibility:hidden;
}

.cssnav ul :hover ul :hover ul :hover ul :hover ul{
visibility:visible;
}

/* All Sub Levels
-----------------------------------*/
/* Default visibility */
.cssnav ul ul {
visibility:hidden;
position:absolute;
top:26px;
left:0;
border-top:1px solid #fff;
}
/* IE Table
-----------------------------------*/
.cssnav table {
position:absolute;
top:0;
left:0;
border-collapse:collapse;
}


/* Support for the "iehover-fix.js" */

* html ul#nav iframe, * html ul.nav iframe {
position: absolute;
/* account for the border */
left: -0.25em;
top: -0.25em;
z-index: 0;
filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);
}

/* this is for IE 5.0
select.hide { visibility: hidden; }
/* End Support for the "iehover-fix.js" */


Link to the JavaScript file (http://tanny.ica.com/ICA/TKO/test.nsf/js/iehover-fix.js)

Phill Pafford
02-02-2009, 08:26 AM
Still looking for a solution

Phill Pafford
02-02-2009, 11:08 AM
Okay I think I've got it now.

Here is how and thanks to all.

From Mr. Nobody (link (http://www.webdeveloper.com/forum/showthread.php?p=974266#post974266)):
That is neither an IE bug nor a JavaScript or CSS issue. In the Windows environment, the SELECT element is not actually an HTML element. Instead, it is borrowed from the operating system and, thus, does not honor the z-index CSS setting. Hence, when you try to display some HTML element over the top of it, the SELECT shows through anyway. There is no real fix for this. The best you can do is set the SELECT to style.display='none' while the DHTML menu is being displayed. If that causes your HTML to shift unpleasantly, then use style.visibility='hidden' instead.

What I changed in the current JavaScript in the Tanny O'Haley's solution (http://tanny.ica.com/ica/tko/tkoblog.nsf/dx/select-tag-overlap-in-ie-part-iii)

Original JavaScript for Tanny O'Haley (http://tanny.ica.com/ICA/TKO/test.nsf/js/iehover-fix.js)

// IE script to change class on mouseover
var ieLIs = nav.getElementsByTagName('li');
for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
// Add a sfhover class to the li.
ieLIs[i].onmouseover=function() {
if(!/\bsfhover\b/.test(this.className))
this.className+=" sfhover";
hideSelects(); // Added this here
}
ieLIs[i].onmouseout=function() {
if(!this.contains(event.toElement))
this.className=this.className.replace(' sfhover', '');
showSelects(); // Added this here
}
}



Now I also needed to change the CSS as well

* html select.hide { visibility: hidden; }


This was IE 5.5 only but I added it to IE6.

This will cause the select element to become hidden so the navigation will display correctly on mouse over. and will re-display on mouse out.




Hope this help someone else in this situation and thanks for all the help with this.

arajapandi
03-17-2009, 03:13 AM
Hi talldean, Thank you very much for your code...