With some DOM scripting, it's possible to create and position an iframe underneath your dropdown for you to fix the problem. Here's a script I wrote to take care of it:
function toggleSelectBox(ID,show) { // ID = the id of the dropdown element DIV (or UL) // show = boolean value to show or hide the dropdown if(!document.getElementById("boxHide")) { // create the iframe if it doesn't already exist var boxHideIframe = document.createElement("iframe"); boxHideIframe.setAttribute("id","boxHide"); boxHideIframe.setAttribute("src","about:blank"); boxHideIframe.setAttribute("scrolling","no"); boxHideIframe.setAttribute("frameBorder","0"); boxHideIframe.style.display = "none"; boxHideIframe.style.position = "absolute"; boxHideIframe.style.top = "0"; boxHideIframe.style.left = "0"; boxHideIframe.style.zIndex = "1"; document.body.appendChild(boxHideIframe); }
var iframe = document.getElementById("boxHide");
if(document.getElementById(ID)) { var subnavmenu = document.getElementById(ID); // show or hide iframe.style.display = (!show) ? "block" : "none";
if(!show) { // set values of iframe to be same as subnav element (these are IE specific) iframe.style.top = subnavmenu.currentStyle['top']; iframe.style.left = subnavmenu.currentStyle['left']; iframe.style.width = subnavmenu.offsetWidth; iframe.style.height = subnavmenu.offsetHeight; } }
}
Basically just add that to your onmouseover and onmouseout JS functions that you use for your dropdown menu. Enjoy.
Thanks JohnRiv. I wasn't able to use your solution exactly, as my dropdowns are CSS based and not initiated via JavScript. But you did point me in the right direction and with some DOM scripting I got it to work.
The above script works very well for select boxes but it fails for certain div with background-colors.The menu falls behind the div which is strange. Any help or suggestion would be great
/* IE 6 and earlier fix - dropdown goes behind select boxes */ .globalNavIframe{display:none;} ul li iframe{display:block;visibility:visible;position:absolute;left:-2000px;top:-2000px;}
/* of course you'll have to put in the correct code for IE6 hover since it doesn't recognize li:hover You can add the IE6 hack so it will be something like: li a:hover iframe */ ul li:hover iframe{display:block;visibility:visible;z-index:-1;position:absolute;margin-top:30px;border:0px;}
/* the height and width will have to be fixed - there may be a way around this now, but I haven't checked */ ul li:hover iframe{top:5px;left:0px;width:150px;height:170px;}
If you want a copy of a working menu, let me know and I can send it to you.