I’ve got a table cell that I would always like to be a particular width. However, it doesn’t work with large strings of unspaced text. Here’s a test case:
td { border: solid green 1px; width: 200px; overflow: hidden; }
<table> <tbody> <tr> <td> This_is_a_terrible_example_of_thinking_outside_the_box. </td> </tr> </tbody> </table>
How do I get the text to be cut off at the edge of the box, rather than having the box expand?
Here is the same problem.
You need to set
table-layout:fixedand a suitable width on the table element, as well asoverflow:hiddenandwhite-space: nowrapon the table cells.Examples
Fixed width columns
The width of the table has to be the same (or smaller) than the fixed width cell(s).
With one fixed width column:
With multiple fixed width columns:
Fixed and fluid width columns
A width for the table must be set, but any extra width is simply taken by the fluid cell(s).
With multiple columns, fixed width and fluid width: