Grow your CSS skills. Land your dream job.

centering tables in XHTML

  • # June 2, 2008 at 8:12 pm

    did a Google serach on how to center a table in XHTML.

    the HTML code "align=center" does not validate in XHTML, it works but does not validate.

    found suggestion that you code "table {margin: 0 auto; text-align: center;}". tried this, and it
    validates in XHTML. found you did not need the "text-align: center" though.

    Al

    # June 2, 2008 at 9:38 pm

    I think the standard is to creat a "wrapper" div. some people call them wrapper and others call them page-wrapper. but the idea is to surround all your content like so

    <html>
    <head>
    </head>
    <body>
    <div id="wrapper">
    Your site content here.

    </div><!–END wrapper div–>
    </body>
    </html>

    then you can make a style sheet for your site

    #wrapper
    {

    margin:0 auto;
    }

    box
    # June 3, 2008 at 5:20 am

    You would need to apply a width property or the margin method won’t work. Also, if its just the table as a whole you wish to have centred in the page…

    Code:
    table{
    margin:0 auto;
    width:500px; /* or whatever width you want */
    }

    I hope this table is being used for tabular data though – and not page layout ;)

    # June 3, 2008 at 10:49 am

    I use a width and margin: 0 auto;

    the table is for tabular data not for layout. I want to rewrite the curling club website
    I maintain http://www.stthomascurlingclub.com which currently makes extensive use
    of tables for layout.

    that is my summer project, conversion of the web site to an XHTML and CSS site only
    using tables for their proper purposes.

    Al

    box
    # June 4, 2008 at 5:23 am

    Good to hear – and good luck :D . One more thing to bear in mind is that you should use a strict doctype – Not only is this better generally and will help you use correct code/mark-up – but it will force IE6 into non-quirks mode and allow the margin:0 auto; to function correctly.

    # June 4, 2008 at 7:33 pm

    I have self-taught myself HTML and CSS with help from some of the online tutorials and
    have tried to use XHTML for the web pages. I have also set them up as STRICT Doctypes.

    Al

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".