Css equivalent of <table align='center'>.. </table>

Discussion in 'CSS' started by fatabbot, Apr 27, 2007.

  1. #1
    Hi,

    I need to get a table in the middle of a container. When I add align='center' to the table it gets centered. But how to get the same result with css? The only attribute there is text-align, which just centers the text inside the table.

    What's the equivalent css style for align='center'?

    Thanks
     
    fatabbot, Apr 27, 2007 IP
  2. webdesigner

    webdesigner Well-Known Member

    Messages:
    489
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    #2
    There is no single center align tag for css. You can do this though:


    body { text-align:center; }
    div { text-align:left; }

    .CenteredDiv { margin-left:auto; margin-right:auto; width:780px; }


    That works in all browsers.
     
    webdesigner, Apr 27, 2007 IP
    fatabbot likes this.
  3. fatabbot

    fatabbot Well-Known Member

    Messages:
    559
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    138
    #3
    cool thanks!
     
    fatabbot, Apr 27, 2007 IP
  4. deques

    deques Peon

    Messages:
    206
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    simplier code

    #wrapper {
    margin: auto;
    width: whatever in pixels;
    }

    this is the wrapper that wraps everything in it
    just use this
    <div id="wrapper">
    ...
    </div>
     
    deques, Apr 27, 2007 IP
  5. sparksflying

    sparksflying Peon

    Messages:
    1,066
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Cool.. wondered this too .. ;)
     
    sparksflying, Apr 27, 2007 IP
  6. webdesigner

    webdesigner Well-Known Member

    Messages:
    489
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    #6
    webdesigner, Apr 27, 2007 IP
  7. diarmuid

    diarmuid Peon

    Messages:
    285
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You just put the CSS tag

    text-align:center;

    Into your CSS sylesheet as per usual under your style name.

    Then just class your table, by using a div or including the class in your body tag or any way you want to:D

    Hope that helps!

    Diarmuid
     
    diarmuid, Apr 27, 2007 IP