36 users online (2 members and 34 guests)  

Thread: Table columns?


  Results 1 to 5 of 5

Related

  1. perl and mysql-compare 2 columns    Forum: CGI Perl Forum
    Replies: 7
  2. Word break for relative columns    Forum: HTML Forum
    Replies: 0
  3. Replies: 3
  4. Replies: 2
  5. columns associated with layers    Forum: CSS Forum
    Replies: 1
  1. #1
    albertemec's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2009
    Posts
    1

    Table columns?

    Hi all, I'm new to the forum and was hoping I could get some quick help, since I am not a web publishing expert.

    I've got a basic table set up with multiple rows but different column widths (i.e. 2 columns in one row, 3 columns in another row, both rows with different column widths). Basically I want each row to span the entire table width. However, it comes out fairly mutated instead :: 1st row becomes 2 filled and 1 empty column, 2nd row becomes 3 columns that are unequally spaced.

    In one row,

    <table width="100%" border="2" bordercolor=BLACK cellspacing="0" cellpadding="10">

    <tr valign="top"><td width="50%" align="center">
    SOME BODY TEXT HERE</p></td>
    <td width="50%" align="center" bgcolor="#FFFFFF">
    SOME BODY TEXT HERE</p></td>
    </tr>

    Closely following that row, another row with::

    <tr valign="top">
    <td width="33.3%">SOME BODY TEXT HERE</td>
    <td width="33.3%">SOME BODY TEXT HERE</td>
    <td width="33.3%">SOME BODY TEXT HERE</td>
    </tr>

    </table>

    What's wrong here?
    PS This is for an HTML e-mail marketing campaign, so I do not believe CSS is an option

  2. #2
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: Table columns?

    You have to think of a table as a grid. You have a set number of columns and each row will have the same number of columns. If you want the setup you mentioned above, then you are going to have to get good at math. Here is your correct structure. The first row will be "hidden", but will define the column widths for the rest of the table. Also remember that if you change the layout at all, you are going to have to change the numbers.

    HTML Code:
    <table width="100%" border="2" bordercolor=BLACK cellspacing="0" cellpadding="10">
    <tr>
    <td width="33%" style="height:0px">&nbsp;</td>
    <td width="17%" style="height:0px">&nbsp;</td>
    <td width="17%" style="height:0px">&nbsp;</td>
    <td width="33%" style="height:0px">&nbsp;</td>
    </tr>
    <tr>
    <td colspan=2 align="center">SOME BODY TEXT HERE</td>
    <td colspan=2 align="center" bgcolor="#FFFFFF">SOME BODY TEXT HERE</td>
    </tr>
    <tr>
    <td valign="top">SOME BODY TEXT HERE</td>
    <td colspan=2 valign="top">SOME BODY TEXT HERE</td>
    <td valign="top">SOME BODY TEXT HERE</td>
    </tr>
    </table>
    Also, if you would prefer, you can move the first line to the bottom line and remove the inline styles if you feel it would not work properly with them. The most important thing is to only define your column widths on one row, not across multiple rows.

  3. #3
    Niche's Avatar
    New User

    Status
    Offline
    Join Date
    Feb 2009
    Posts
    3

    Re: Table columns?

    I was going to say use CSS, makes life much easier but you seem not to want to go that way
    The alternative to the above suggestion is to have one big table and insert your rows as different tables within the big table. Make sure the borders are zero pixels and they should fit nicely

  4. #4
    carolin's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2010
    Posts
    9

    Re: Table columns?

    to span out the rows and columns we can use rowspan and colspan attributes in the table data tag..

  5. #5
    ArtphotoasiA's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Dec 2009
    Location
    Italy
    Posts
    31

    Re: Table columns?

    Quote Originally Posted by Niche View Post
    I was going to say use CSS, makes life much easier
    This is not really true, sometimes css are more complicated managing a grid of contents .... if is a simple layout I go for css if example I need to make a grid 3x3 with contenents updated often and with different arrangement I go for a table as is more friendly specially if need to merge row or column.

    My 2 cents.