Word Wrapping in CSS/JS: A Cross-Browser Solution
The challenge of wrapping long strings of text within predetermined DIV widths without scrolling has long plagued web developers. To address this, various approaches have been explored, each with its own limitations.
Despite promising candidates like "word-wrap: break-word" and "
Eureka! CSS to the Rescue
Finally, a breakthrough emerges in the realm of CSS:
.wordwrap { white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ }
Utilizing this CSS rule, developers can seamlessly achieve cross-browser word wrapping without the pitfalls of previous methods. Additionally, you can employ the "word-wrap: normal;" rule to revert to default wrapping behavior.
This solution elegantly addresses the challenge of word wrapping, empowering developers to display long URLs and other uninterrupted text strings in an aesthetically pleasing and browser-compatible manner.
The above is the detailed content of How to Achieve Cross-Browser Word Wrapping in CSS/JS?. For more information, please follow other related articles on the PHP Chinese website!