471,852 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

Centering a DIV

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:


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:


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.



Sep 9 '06 #1
2 1499
7,435 Expert 4TB
In your css put 'margin: 0 auto;'
Sep 10 '06 #2
9,065 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
reply views Thread by NeoPa | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.