How to implement forced line wrapping of long words in DIV?
P粉450744515
2023-08-21 14:03:56
<p>Okay, this really confuses me. I have some content inside a </p><div> like this: <p><br /></p>
<pre class="brush:php;toolbar:false;"><div style="background-color: green; width: 200px; height: 300px;">
Thisisatest.Thisisatest.Thisisatest.Thisisatest.Thisisatest.Thisisatest.
</div></pre>
<p>However, the content overflows the </p><div> (as expected) because the "word" is too long. <p><br /></p>
<p>How do I force the browser to "break" words when necessary to fit everything? </p></div></div>
I’m not sure about browser compatibility
You can also use the
<wbr>
tagUseword-wrap:break-word;
This works even in IE6, which is a pleasant surprise.
word-wrap: break-word
has been replaced byoverflow-wrap: break-word;
, which works in all modern browsers. Since IE is an outdated browser, it will always rely on the deprecated and non-standardword-wrap
.The current case of using
word-wrap
will still work fine as it is an alias for the canonicaloverflow-wrap
.