[RESOLVED] Centering a table
Results 1 to 9 of 9

Thread: [RESOLVED] Centering a table

  1. #1
    Join Date
    Aug 2007
    Posts
    13

    Resolved [RESOLVED] Centering a table

    I am trying to center a table that I have in a website that I am building. However I need to know how to center the table in the middle of the screen. I already tried the <h2 align="center"> tag. That didn't work. If you could help me that would be greatly appreciated.

    thanks,
    will

  2. #2
    Join Date
    Apr 2005
    Location
    Maryland, USA
    Posts
    17,806
    Enclose your table with the <center></center> tags. For example:
    Code:
    <html>
     <title>Hello World!</title>
    <body></body>
    
     Not centered:<br>
     <table width="50%" border="10" cellpadding="7" cellspacing="1">
      <tr>
       <td align="center">
        <br>
        <font face="verdana", "helvetica", "arial">
         Hello World!
        </font"
        <br>
        <br>
       </td>
      </tr>
     </table> 
     <br>
     <br>
    
     Centered:<br>
     <center>
      <table width="50%" border="10" cellpadding="7" cellspacing="1">
       <tr>
        <td align="center">
         <br>
         <font face="verdana", "helvetica", "arial">
          Hello World!
         </font"
         <br>
         <br>
        </td>
       </tr>
      </table> 
     </center>
    </html>

  3. #3
    Join Date
    Aug 2007
    Posts
    13

    Centering a table

    I tried that with my table and that didn't work the way that I wanted it to. Here is the code for the table:
    Code:
    <table border="1">
    <tr>
    <td><b>September:</b> Children's' Eye Health & Safety Month - Internet Safety Month - Library Card Sign-Up Month!</td>
    </tr>
    <tr>
    <td>September 2, Labor Day</td>
    </tr>
    <tr>
    <td>September 5, <a href="http://www.potsdam.k12.ny.us/AAK/">AAK</a>,Open House</td>
    </tr>
    <tr>
    <td>September 11, <a href="http://www.potsdam.k12.ny.us/District/BOE/BoardMembers.php">BOE</a>,meeting @ 7pm in the High school library</td>
    </tr>
    <tr>
    <td>September 13, <a href="http://www.potsdam.k12.ny.us/LA/">Lawrence Ave</a>,Open House</td>
    </tr>
    <tr>
    <td>September 19, <a href="http://www.potsdam.k12.ny.us/District/PTA/">PTSA</a>,General Membership meeting in the LGIR @ 7pm.</td>
    </tr>
    <tr>
    <td>September 25, <a href="http://www.potsdam.k12.ny.us/Distric/BOE/BoardMembers.php">BOE</a>, Meeting @ 7pm in the High school library
    </tr>
    </table>

  4. #4
    Join Date
    Nov 2004
    Posts
    152
    As spywaredr stated, it's the perfect way to center with basic html......Right after the "body" tags, type in <CENTER>...put in your table, and after you end your table, put in </CENTER>...Look at the code sp'wr'dr, included, the second part, you'll see what (we) mean.

  5. #5
    Join Date
    Nov 2004
    Posts
    152
    Your table, verbatim below......Before your code, "<TABLE BORDER="1">..... place <CENTER">
    <table border="1">
    <tr>
    <td><b>September:</b> Children's' Eye Health & Safety Month - Internet Safety Month - Library Card Sign-Up Month!</td>
    </tr>
    <tr>
    <td>September 2, Labor Day</td>
    </tr>
    <tr>
    <td>September 5, <a href="http://www.potsdam.k12.ny.us/AAK/">AAK</a>,Open House</td>
    </tr>
    <tr>
    <td>September 11, <a href="http://www.potsdam.k12.ny.us/District/BOE/BoardMembers.php">BOE</a>,meeting @ 7pm in the High school library</td>
    </tr>
    <tr>
    <td>September 13, <a href="http://www.potsdam.k12.ny.us/LA/">Lawrence Ave</a>,Open House</td>
    </tr>
    <tr>
    <td>September 19, <a href="http://www.potsdam.k12.ny.us/District/PTA/">PTSA</a>,General Membership meeting in the LGIR @ 7pm.</td>
    </tr>
    <tr>
    <td>September 25, <a href="http://www.potsdam.k12.ny.us/Distric/BOE/BoardMembers.php">BOE</a>, Meeting @ 7pm in the High school library
    </tr>
    </table> </CENTER>.... is what goes after the table...copy and paste the preceding code into your html editor, without my blurbs, you'll see what happens.

  6. #6
    Join Date
    Nov 1999
    Location
    California, USA
    Posts
    501
    Change this...
    <table border="1">
    to this...
    <table border="1" align="center">

    No other changes needed.


    "If you look at the sun without shielding your eyes, you'll go blind.
    If you look at the moon without covering your eyes, you'll become a poet."
    --Serge Bouchard

  7. #7
    JPnyc is offline Virtual PC Specialist!!!
    Join Date
    Jan 2005
    Posts
    7,877
    center tags will center anything you put them around. It's the old fashioned way, but it still works. The new way would be to set the tables margin to auto in your css, for firefox and opera. For IE, you'd probably need to put text-align:center on the body element, which would center the table (and any other elements)
    There is nothing to fear, but life itself.

  8. #8
    Join Date
    Aug 2007
    Posts
    13

    Smile

    Thanks for the help. I finally got what you guys were saying.

  9. #9
    Join Date
    Apr 2005
    Location
    Maryland, USA
    Posts
    17,806
    You're welcome.

    Pretty easy once you grasp the concept.
    <center>

    Whatever's written in here between the "center" tags will be centered on the web page.


    </center>
    Last edited by SpywareDr; September 5th, 2007 at 05:09 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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