HTML
<table >
<tr>
<td>veeeeeeeeeeeeeeeeeeeeery looong</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
CSS
table {
width: 80px;
}
td {
overflow: hidden;
max-width: 25%;
width: 25%;
}
I want every column to be 25% of 80px, thus 20px in size. How do I stop the first column from getting larger (its content can be hidden).
The best possible solution for this is the one you are using now. Since you cannot predict the number of columns you cannot set a width to each column. So setting the overflow of the parent div to auto and the child table width to 100% is the best solution.
The width of the columns i.e. td in a table can be fixed very easily. This can be done by adding the width attribute in the <td> tag. If the width is not specified, the width of the column changes according to the change in the content. The specifications of width for the columns can be in pixels, or percentage.
If you set the style table-layout: fixed; on your table, you can override the browser's automatic column resizing. The browser will then set column widths based on the width of cells in the first row of the table. Change your to and remove the inside of it, and then set fixed widths for the cells in .
You could use table-layout: fixed
table {
width: 80px;
border: 1px solid #333;
table-layout: fixed;
}
td {
overflow: hidden;
max-width: 25%;
width: 25%;
border: 1px solid #333;
word-wrap: break-word;
}
An example: http://jsfiddle.net/wsastn47/1/
edit: @mevius suggestion word-wrap: break-word;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With