Home > Article > Web Front-end > How to Ensure Text Wrapping in Table Cells Across All Browsers?
CSS for Text Wrapping within Table Cells
In cases where text within a table cell needs to wrap, it is essential to consider browser compatibility. While the use of word-break: break-all; and table-layout: fixed; may suffice for Chrome, it might not work as expected in Firefox.
Cross-Browser Compatibility
To address this browser compatibility issue, a more comprehensive CSS solution can be employed:
.wrapword { white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */ white-space: -webkit-pre-wrap; /* Chrome & Safari */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ white-space: pre-wrap; /* CSS3 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ word-break: break-all; white-space: normal; }
This CSS ensures that text will wrap properly in various browsers. By applying the wrapword class to a table cell, the text will break automatically without any unwanted whitespace:
<table>
Using this technique, text within table cells can be wrapped effectively, maintaining cross-browser compatibility.
The above is the detailed content of How to Ensure Text Wrapping in Table Cells Across All Browsers?. For more information, please follow other related articles on the PHP Chinese website!