View Full Version : How to position a layer?

01-07-2003, 08:01 PM

I have a web page with a simple navigation bar. When a user moves a mouse over a picture in navigation bar, a layer appears with "deeper" links. But I have a problem - how to position the layer, so that it appears directly bellow the picture? I tried:
style="position:absolute; left:230; top:138; width:116; height:120; but it doesnt work, because my page (table) is centered in a browser, so that the left coordinate varies, depending on the size of browser's window.

I was also experimentig with:
position:relative...but had no success.

What would you recomend?

Bostjan :thumbsup:

01-07-2003, 09:18 PM
use a percentage(%) or use some javascript to detect the users screen size and position it accoridingly.


01-08-2003, 12:29 AM
Yeah, I agree with scroots. I would use some javascript to position it. The gist of the script would be to determine the total width of the screen, divide that by two, then subtract whatever you need to in order to get the right positioning for the div.

I am not very good with this stuff, but I would imagine the script would look like this:
var width = screen.availWidth
var center = width/2
var myLeft = center - (your amount needed)

Then in your body tag do something like this:

document.write("<div style='position: absolute; left:" + myLeft + "; top: 138; width: 116; height: 120;'>")
(All your content in your div goes here)

That should do it I would imagine, just play aroud with the numbers a little bit and it should work out.

If it really concerns you though, you could always just position everything absolutley then you wouldn't run into these problems, but that can be a mess if it requires reformatting the code.

01-08-2003, 07:28 AM
z-index will allow the div to float above all the elements regardless.
but i cant say its the best way to go, because i dunno about your menu.