Centering a DIV

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johnmr
    New Member
    • Sep 2006
    • 6

    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:

    http://www.artntech.co m/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.co m/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

    *
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    In your css put 'margin: 0 auto;'

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      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.

      Comment

      Working...