469,346 Members | 6,562 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,346 developers. It's quick & easy.

Centering a DIV

6
I am building an interface where I have a DIV that gets made visible when you roll over a certain area. The div contains some nav elements, which are jscript rollovers themselves. I've got the code working to hide and show the DIV and to do the rollovers. Here is what it looks like so far:

http://www.artntech.com/sample/index.html

The problem is, I really want the design to be centered, and since I am using absolute positioning for the DIV, this creates a problem. Here is what it looks like when I center the underlying table:

http://www.artntech.com/sample/index2.html

I'm pretty new to all his, and am stumped as to how to get that DIV element to center and align with the underlying table (since it is centered, I can't really predict exactly where it will be in the window).

I've seen articles saying this kind of thing can be one with CSS and have tried several of the samples I've seen with no luck. Anyone know of a good way to do this? Any help greatly appreciated.

Thanks

Johnmr

*
Sep 9 '06 #1
2 1457
drhowarddrfine
7,435 Expert 4TB
In your css put 'margin: 0 auto;'
Sep 10 '06 #2
Banfa
9,064 Expert Mod 8TB
If you have to use absolute positioning (which I personally think is a mistake) then put you absolutely positioned elements inside a non-absolute positioned element.

Give that element a style of display: relative; no need to set left or top just let them default to zero.

What this does is cause the absolutely position elements to take the location of their relatively positioned parents as the origin (0,0) rather than the top left corner of the page.

Then you can centre the relatively positioned element and all your absolutely positioned elements will follow suit.
Sep 10 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by Jeff Thies | last post: by
6 posts views Thread by Fran¨ois de Dardel | last post: by
3 posts views Thread by Jonah Bishop | last post: by
2 posts views Thread by Ryan W Sims | last post: by
9 posts views Thread by Pierre Jelenc | last post: by
15 posts views Thread by red | last post: by
6 posts views Thread by Axel Siebenwirth | last post: by
3 posts views Thread by John Pote | last post: by
5 posts views Thread by Markus Ernst | last post: by
1 post views Thread by =?Utf-8?B?ZnJhbmt5?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.