View Full Version : setting maximum width for table cell
gib65
04-21-2010, 10:18 PM
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.
BLiZZaRD
04-21-2010, 11:04 PM
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.
<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.
gib65
04-22-2010, 12:53 AM
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.
BLiZZaRD
04-22-2010, 01:18 AM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.