Home >Web Front-end >CSS Tutorial >How can I make text wrap in a table cell?
By default, table cell text does not automatically wrap to the next line, causing text to overflow outside the cell and affecting the layout of the page.
There are two main methods to force table cell text wrapping:
This sets a fixed layout for the table and forces text to break into multiple lines within the cell's width. It works in modern browsers.
<br>table {<br> table-layout: fixed;<br>}</p> <p>td {<br> word-wrap: break-word;<br>}<br>
This instructs the browser to treat cell text as normal text, allowing it to wrap naturally. However, it may not work in all browsers.
<br>td {<br> white-space: normal;<br>}<br>
Depending on your page layout, you may also need to adjust the width of the table or cell to ensure the text wraps as desired.
Additionally, if the table is within a flexible container, such as a div with a percentage width, the cell text might still overflow the container due to the dynamic nature of the layout.
The above is the detailed content of How can I make text wrap in a table cell?. For more information, please follow other related articles on the PHP Chinese website!