Results 1 to 3 of 3

Thread: Centering A Table Using CSS

  1. #1
    Join Date
    Jun 2005
    Location
    Scotland
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Centering A Table Using CSS

    OK! I'm thick! What's the CSS positioning code for aligning a table on the center of a page, either horizontally, vertically or both?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    They haven't decided yet. Try:

    table {
    margin:0 auto;
    }
    * html table {
    margin: 0 20%:
    }

    That's horizontal centering, I imagine vertical would be the opposite and both would be auto auto and 20% 20% respectively but, vertical centering is an odd concept and might not be supported.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    They haven't decided yet.
    It was decided years ago. Blame browser manufactures for poor (or no) implementation.

    See http://css-discuss.incutio.com/?page...ngBlockElement. Note that vertical centring is a real pain in the ass because of poor CSS support, particularly from IE.

    That's horizontal centering, I imagine vertical would be the opposite and both would be auto auto and 20% 20% respectively
    No, that wouldn't work without extra effort, but it's close:

    Code:
    <selector> {
      position: absolute;
    
      height: ...;
      margin: auto 0;
    
      top: 0; bottom: 0;
    }
    If you added similar declarations for horizontal dimensions, you'd get horizontal centring, too. However, you can guess where this doesn't work.

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •