Overflow:hidden may not work as expected in
The crux of the problem lies in the default behaviour of table elements. Tables typically use a fluid layout, where cell widths expand and contract based on content. To override this, we must specify a fixed table layout:
table { table-layout: fixed; }
Additionally, setting a fixed width on the table container limits the overall size available to the table cells:
table { ... width: 200px;
Finally, to truly constrain the cell's content, we apply overflow:hidden to the table cells and white-space: nowrap to prevent word wrap:
td { ... overflow: hidden; white-space: nowrap; }
These combined tweaks ensure that text content is truncated at the edge of the cell, preventing it from overflowing.
Consider this modified example:
<table>
Now, the text will be cut off at the 100px cell width, as desired.
The above is the detailed content of Why Isn't `overflow: hidden` Working in My Table Cells ()?. For more information, please follow other related articles on the PHP Chinese website!