Results 1 to 4 of 4

Thread: setting maximum width for table cell

  1. #1
    Join Date
    Jun 2008
    Posts
    107
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default setting maximum width for table cell

    Is there a way to limit the width of a table cell (upper limit)? I tried the max-width thing in both the table and td tags and it doesn't work.

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,486
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Apply the width and height attributes to your <td> tags to explicitly set the dimensions of your table cells and thus exercise control over the width and height of rows and columns.

    Code:
    <td width="80%">blah blah content</td>
    In the case where the width attribute is set in more than one cell in the same column, the largest width is the one that is applied. Likewise, if the content in any table cell in that column (such as a graphic) outsizes a specified width, the width of the content will establish the width of the cell and the column it resides in.
    {CWoT - Riddle } {OSTU - Psycho} {Invasion - Team}
    Follow Me on Twitter: @Negative_Chaos
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Jun 2008
    Posts
    107
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    The thing is, though, I would like the cell to adjust to the width of its contents, but only below a specified maximum width. Setting the width to something like 80% would make it fixed and not adjust at all.

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,486
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    If you do not specify a width or height attribute, then the cell automatically adjusts to its contents. The thing is, if you have 3 cells on top of each other in a column, and 3 rows the same way, the rows and the columns will adjust each cell to the tallest and widest one. so if the cell at position 1 - 4 is the tallest at say 100 pixels, and cell at position 3 - 2 is the widest at 300 pixels ALL cells will be 100px X 300 px. No matter what.

    Setting a cell width (or height) is a pixel ( read: fixed) or a percentage (read: adjustable) but ONLY to the total size of the table they are contained in.

    If you have a table that is 1000 pixels wide, and you have 2 cells inside, with no attributes, each will adjust to 50% of the width. If you tell the cells to be 40% and 60% with no cell padding or spacing, then they will do that as well.

    Adjusting to the size, as you are wanting will need to be done based on the largest item you are using the table for, OR, drop the tables and use DIVs.

    Hope that helps.
    {CWoT - Riddle } {OSTU - Psycho} {Invasion - Team}
    Follow Me on Twitter: @Negative_Chaos
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

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