Forum Moderators: not2easy

Message Too Old, No Replies

This must be possible (z-index and relative)

This must be possible (z-index and relative)

         

Perfect Member Name

10:33 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



This is pretty tricky, and I haven't done a very good job of explaining it in the past.

I have a fluid website that appears different based on browser resolution. I'm trying to create a dynamic menu that appears when an image is clicked. The top of the menu should align with the bottom of the image. The menu should have a high z-index so it floats above content on the page.

Since the location of the image can change based on resolution, I can't absolutly position it. Can anyone help me figure this out?

I've posted a few illustrations of what I'm going for here [framezero.com].

If anyone can figure out how to do this, I'd be amazed and grateful.

DrDoc

10:53 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oh yes you can position it absolutely ;)

<html>
<head>
<title>Untitled</title>
<style type="text/css">
#main li {
background-color: red;
border: 1px solid black;
position: relative;
}
#foo {
position: absolute;
left: 0;
top: 1.25em;
background-color: teal;
height: 300px;
width: 400px;
display: none;
}
</style>
</head>
<body>
<!-- insert text here-->
<ul id="main">
<li><a href="#" onclick="document.getElementById('foo').style.display='block';return false;">test</a>
<span id="foo">And here's some text... blah blah blah</span></li>
</ul>
</body>
</html>

Perfect Member Name

11:11 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



Whoa... You sir, are a ninja. Thank you very much.

DrDoc

11:16 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The key to it working is that the parent has to be positioned too. However,
position:relative
by itself is not going to move the element. So we just created a positioned element without affecting the layout one bit. The child is then positioned according to the top left corner of its parent. And, voila! we have relative absolute positioning ;)

Perfect Member Name

1:13 am on Feb 10, 2004 (gmt 0)

10+ Year Member



Actually, there is one more thing. The "main" div is on a line of code with some other elements:

[headline] [some text] [click here for menu] [something else]

Wrapping the image (seen above as [click here for menu]) in a div tag forces it onto its own line on the page. I tried replacing the div tags with span tags, which works in IE but does not in mozilla.

Is there any way to use a div, but not have it go onto its own line?

DrDoc

3:46 pm on Feb 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There sure is... display:inline :)

Perfect Member Name

9:23 pm on Feb 10, 2004 (gmt 0)

10+ Year Member



display: inline corrected the breaks created by the DIV and my page is now laid out correctly.

However... adding display: inline to the "main" id in your above example creates a few new problems for Mozilla.

The ability interact with the data in the "foo" span has been lost. Previously, I could highlight the "And here's some text" text. I actually need to have checkboxes and form fields in the "foo" span, and those also lose interaction ability with display: inline.

This feels like it's really, really close now. Thank you for all the help thus far.