Results 1 to 8 of 8

Thread: CSS Tables, Table Align

  1. #1

    Thread Starter
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274

    CSS Tables, Table Align

    Howdy doo
    I've created a new (offline) website using standard html and it looks good enough to attract women but I was thinking to myself that I might take a look at this CSS stuff. Well, it all looks pretty straightforward but I have one 'conceptual' question and one 'technical' question

    • Is the use of Tables still acceptable in CSS and if acceptable is it best practice? (I read a bit about positioning 'blocks')

    • If Tables are the way to go how is it possible to centre align a table (the whole table) on the page. There is no align attribute of Tables in css and I have tried other answers that i found (margin_left/right: auto) but that didnt work either. Any ideas???
    Ta muchly.
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  2. #2
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    1/ Tables is still acceptable because CSS still has no acceptable way of creating tables, at least not until the new version arrives. You can use the <span> or <div> HTML Tag and use CSS to align it but I think this is really fiddly at times

    2/ Yes it is. You cane either use align="center" in the table tab (shown in code below) or you can put the whole table in <center> </center> tags.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Quick Tables Question</title>
    </head>
    <body>
    <table border="1" width="50%" align="center">
    <tr align="center">
    <td>Column 1</td>
    <td>Column 2</td>
    </tr>
    <tr align="center">
    <td>Column 1</td>
    <td>Column 2</td>
    </tr>
    </table>
    </body>
    </html>

    But I advise you to give CSS/DHTML a go, you might like it
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  3. #3

    Thread Starter
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    • Thks for ur answer. I understand that u can use the table align tags within the html page but why is it that u cant set it in the css file like u can with all other table attributes? Is it normal to set all attributes in css and still do this...

    <table class="blugh" align="center"> .....

    • When u say Css/dhmtl .. i take it that u still mean css version 2? k? Yeah i do want to use it but is only an hour since i decided to .. it looks pretty easy but will take a little getting used to
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  4. #4
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    Its probably better practice to use CSS to align text in a table.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Quick Tables Question</title>

    <style type="text/css">
    <!--
    table {text-align: center}
    -->
    </style>

    </head>
    <body>
    <table border="1" width="50%" center="align">
    <tr>
    <td>Column 1</td>
    <td>Column 2</td>
    </tr>
    <tr align="center">
    <td>Column 1</td>
    <td>Column 2</td>
    </tr>
    </table>
    </body>
    </html>

    DHTML is a a mixture of CSS/HTML and Javascript/VBScript. Basically, you use CSS for page layout or the HTML tags and you use a scripting language to controll and dynamic user input, hence Dynamic Hypertext Markup Language
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  5. #5

    Thread Starter
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    thanks but i dont think that u are answering the question I asked. i am not concerned with the text alignment but with how the table appears on the screen. u have set text align in css and then used table align in html. I am asking if u can use some method to align the table (not the text) in css rather than having to do it in html.
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  6. #6
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    Sorry, yeah, I mis-read the question. Anyhoo... according to CSS specifications the suggested way to center a table is to set the left and right margins to auto. But I dont think this works most of the time.

    The best way (In my opinion) is to put the table in a Div and center the Div like this : -

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Quick Tables Question</title>

    <style type="text/css">
    <!--
    div.centered {text-align: center;}
    div.centered table {margin: auto; text-align: center;}
    -->
    </style>

    </head>
    <body>
    <div class="centered">
    <table border="1" width="50%">
    <tr>
    <td>Column 1</td>
    <td>Column 2</td>
    </tr>
    <tr align="center">
    <td>Column 1</td>
    <td>Column 2</td>
    </tr>
    </table>
    </div>
    </body>
    </html>

    ...which works fine in IE and Netscape.
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  7. #7

    Thread Starter
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Cool thanks
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  8. #8
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032

    Re: CSS Tables, Table Align

    Originally posted by beachbum
    Howdy doo
    I've created a new (offline) website using standard html and it looks good enough to attract women but I was thinking to myself that I might take a look at this CSS stuff. Well, it all looks pretty straightforward but I have one 'conceptual' question and one 'technical' question

    • Is the use of Tables still acceptable in CSS and if acceptable is it best practice? (I read a bit about positioning 'blocks')
    In theory, with CSS, you should only use tables for presenting tabular data, not for layout/presentation. In reality, lots of people are going to use tables anyway. Do a search for "table-less CSS layout" or related terms and you should get some interesting links.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

Posting Permissions

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



Click Here to Expand Forum to Full Width