34 users online (1 members and 33 guests)  


  Results 1 to 7 of 7

Related

  1. How do I align Text in the same line?    Forum: HTML Forum
    Replies: 10
  2. IE 6 text-align center problem    Forum: HTML Forum
    Replies: 5
  3. Align text with an image link?    Forum: HTML Forum
    Replies: 2
  4. text-align center problem - only in ie6    Forum: CSS Forum
    Replies: 4
  1. #1
    J-Man's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2003
    Posts
    32

    Align text to Centered table

    I have some text that is written above a table. I want the table centered on the page and the text above the table, left justified to the table. In other words, I don't want the text left-justified on the page...I want it left-justified to the table below it. I looked at centering a table that contains the text and the original table, but I still can't get the text to left justify...it always shows up centered. Any ideas??? Any small examples of how to do this? Thanks in advance!!

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732
    Hi there J-Man.

    Do you mean like this...
    Code:
    <html>
    <head>
    
    <style type="text/css">
    <!--
    div
        {
         position:absolute;
         left:50%;
         margin-left:-200px;  //-- this is half the table width
        }
    td#one
        {
         border:solid 1px #000000;
         width:400px; 
         height:300px;
         text-align:center;
        }
    //-->
    </style>
    
    </head>
    <body>
    
    <div>
    <table><tr>
    <td>Text on the left</td>
    </tr><tr>
    <td id="one">Table cell</td>
    </tr></table>
    </div>
    
    </body>
    </html>
    cthead

  3. #3
    J-Man's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2003
    Posts
    32
    coothead,

    That is what I'm looking for. However, I don't know the table width and I'd like to do this without CSS. Any other ideas?

    Thanks again!!!

  4. #4
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732
    Hi there J-Man,

    well, of course, if you do not mind using deprecated code
    just use this.... and add whatever attributes you require

    <center>
    <table><tr>
    <td>Text on the left</td>
    </tr><tr>
    <td align="center">Table cell</td>
    </tr></table>
    </center>

    cthead

  5. #5
    J-Man's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2003
    Posts
    32
    Quote Originally Posted by coothead
    <center>
    <table><tr>
    <td>Text on the left</td>
    </tr><tr>
    <td align="center">Table cell</td>
    </tr></table>
    </center>
    cthead
    That works great with the example that you are using...but, I have another added twist. I need to do the below (notice the table within a table)...but, the "Text on the left" is always centered. Any ideas?

    Code:
    <center>
    <table><tr>
    <td>Text on the left</td>
    </tr><tr>
    <table><tr>
    <td align="center">Table cell</td>
    </tr></table>
    </tr></table>
    </center>

  6. #6
    J-Man's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2003
    Posts
    32
    After much trial and error, I've come up with the solution:
    Code:
    <center>
    <table><tr>
    <td>Text on the left</td>
    </tr><tr>
    <td>
    <table><tr>
    <td>Table cell</td>
    </tr></table>
    </td>
    </tr></table>
    </center>
    [/QUOTE]

    Notice the placement of the <td> and </td> around the inner table!!!

  7. #7
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    Content must always be placed within td tags, this includes nested tables. Your previous code <tr><table> is a no-no

    Dave



Tags for this Thread