Forum Moderators: open

Message Too Old, No Replies

Position absolute elements infront of select elements?

         

benj0323

4:25 am on Jul 21, 2005 (gmt 0)

10+ Year Member



I'm using a javascript drop down menu and when the menu pops up it pops up behind any select boxes that are in its path. It ONLY does this in IE. Firefox handles it fine. I played with the z-index and nothing happens.

Any ideas or am I screwed due to microsoft's ignorance?

dreamcatcher

7:23 am on Jul 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, there is no fix for this I don`t think. Its a problem with IE and I believe earlier versions of Netscape.

[webreference.com...]

benj0323

3:10 pm on Jul 21, 2005 (gmt 0)

10+ Year Member



I wonder what brainiac at Microsoft decided to make select boxes different from every other element on a web page. I'd like to hear the logic behind that decision.

I find myself making more work arounds, so my web page functions right in IE, than I do any other browser.

benj0323

3:24 am on Jul 22, 2005 (gmt 0)

10+ Year Member



I've been playing around with things, and after hours of testing I have come up with a solution. Essentially you have to place an inframe behind any absolute positioned elements with a z-index less than the absolute element. Iframes move in front of select boxes and can have a z-index to allow other elements to be placed in front of it.

I hope this helps.

john_k

4:05 am on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ha - the iframe trick works pretty slick (at least with my quick tests of it). I have run into this select list issue in the past and we just toggled the visibility of the select lists to the opposite of the menu div.

Playing around with your iframe idea I found one neat side effect. If you set the iframe position to be to the right of the div by several pixels, the select list will appear to split through your div. The part of the select list that is covered by the iframe will be hidden as if it is behind the div, and the part that is not covered by the iframe still sits on top.

john_k

4:23 am on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is what I was talking about...

<html>
<head>
<title>Test01</title>
</head>
<body>

<div style="{position:absolute;background-color:#ff0000;left:50px;top:50px;width:200px;height:200px;z-index:1;}">
howdy
</div>

<div style="{position:absolute;left:70px;top:60px;z-index:2;}">
<select id="lstTest" name="lstTest">
<option>one</option>
<option>two</option>
<option>three</option>
<option>four</option>
</select>
</div>

<div style="{position:absolute;background-color:#0000ff;left:90px;top:70px;width:200px;height:200px;z-index:4;}">
Howdy again
</div>

<iframe name="fTest" id="fTest" style="{position:absolute;left:100px;top:70px;width:190px;height:200px;z-index:3;}"></iframe>

</body>
</html>

(sorry about drifting off-topic, but I am very easily amused when in serious need of sleep)

tedster

5:34 am on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Interesting discussion - and quuite the nifty hack with iframe, john_k

I wonder what brainiac at Microsoft decided to make select
boxes different from every other element on a web page. I'd like
to hear the logic behind that decision.

I think it's more of a legacy issue than an intentional decision. Note this reference from the W3C's HTML 3.2 recommendation:

INPUT, SELECT and TEXTAREA are only allowed within FORM elements.

[w3.org...]

In older browsers, form elements actually acted as if they were SENIOR to the document body - more like a part of the operating system in the way that scrollbars are. You could observe this "senior" quality in the way pages loaded and unloaded over a nice, slow dial-up modem on a nice slow Windows 3.2 system (but this is not the time or place for such nostalgia.)

So this quirky behavior put all form elements, including <select> lists, "on top" of the rest of the page. This legacy behavior of forms and their elements made for many oddities, including the slow, slow development of complete browser support for css in form elements. And some of it still hangs on in the spaghetti code we all know and love as IE6

In fact, I just had to run a validation test to assure myself that <select> will validate when it's not inside <form>. It does. I don't know exactly when that change happened, but given the reference I found above I assume it came in with html 4.

Robin_reala

6:22 am on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So anyone good enough at Javascript willing to make a script that iterates through the DOM and creates an positioned and sized iframe on top of every <select>? That way we could just call it whenever the menu is used and not worry about it again...

john_k

7:15 am on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't need one on top of every select - just one behind each menu div. That should be much easier since the function that shows/hides the div would already know the position and size of the div (or could easily get it).

benj0323

9:21 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



Basically how you move iframes around the page is up to you.

John K has it right. Here is a sample HTML document:

<html>
<head>
<script>
function ChangeVis(state)
{
var DivRef = document.getElementById('SomeDive');
var IfrRef = document.getElementById('SomeIframe');
if(state)
{
DivRef.style.display = "block";
IfrRef.style.width = DivRef.offsetWidth;
IfrRef.style.height = DivRef.offsetHeight;
IfrRef.style.top = DivRef.style.top;
IfrRef.style.left = DivRef.style.left;
IfrRef.style.zIndex = DivRef.style.zIndex - 1;
IfrRef.style.display = "block";
}
else
{
DivRef.style.display = "none";
IfrRef.style.display = "none";
}
}
</script>
</head>
<body>
<form>
<select>
<option>Some options....</option>
</select>
</form>
<div
id="SoemDiv"
style="position:absolute; top:25px; left:50px; padding:4px; display:none; background-color:#000000; color:#ffffff; z-index:100">
.... and a DIV can cover it up<br>through the help of an IFRAME.
</div>
<iframe
id="SomeIframe"
src="javascript:false;"
scrolling="no"
frameborder="0"
style="position:absolute; top:0px; left:0px; display:none;">
</iframe>
<br>
<br>
<a href="#" onclick="ChangeVis(true)">Click to show DIV.</a>
<br>
<br>
<a href="#" onclick="ChangeVis(false)">Click to hide DIV.</a>
</body>
</html>

Robin_reala

12:34 am on Jul 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Trouble is, I don't want to load my html up with elements that are specifically designed to hack a particular browser; having a 'fix select' script that I could link in with conditional comments would be nicer. Shame I'm no Javascript expert.

benj0323

3:26 am on Jul 23, 2005 (gmt 0)

10+ Year Member



You dont even see the iframe. If you wanted you could only execute that javascript code for IE by using a browser detect script.

Other than that there is no other fix for this problem.

Tracq

9:03 am on Jul 27, 2005 (gmt 0)



I've been looking for a solution to this everywhere and most forums are saying the same thing that is to use iframes. Not being much of a coder I wonder if anyone could help me.

I'm using a Milonic menu that is call within a page call header.asp like this

<script language=JavaScript src="/T&DSchedule/menu_array.js" type=text/javascript></script>
<script language=JavaScript src="/T&DSchedule/mmenu.js" type=text/javascript></script>

then header.asp is called via an Include statement to every page within the site.

Some pages contain select boxes, that I can't re-position, and the menu is dropping out behind them.

Sorry I'm getting to the point.

How do I make this iFrame thing work when I hover over a milonic menu Item that has a drop out?

I'd appreciate any help.