Home >Web Front-end >CSS Tutorial >How to Prevent Table Cell Expansion Due to Long Text?
In a typical table layout, the width of a column adjusts to accommodate the length of its longest cell. However, if you desire a fixed column width regardless of the text within its cells, follow these steps:
Solution:
Example:
table { table-layout: fixed; width: 200px; } th, td { width: 100px; overflow: hidden; }
<table> <tr> <th>header 1</th> <th>header 234567895678657</th> </tr> <tr> <td>data asdfasdfasdfasdfasdf</td> <td>data 2</td> </tr> </table>
By adhering to these steps, you can ensure that table column widths remain fixed, regardless of the text length in its cells. This approach grants you greater control over table presentation and prevents unwanted column expansion that may disrupt your layout.
The above is the detailed content of How to Prevent Table Cell Expansion Due to Long Text?. For more information, please follow other related articles on the PHP Chinese website!