search

Home  >  Q&A  >  body text

How to implement forced line wrapping of long words in DIV?

<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>
P粉450744515P粉450744515453 days ago386

reply all(2)I'll reply

  • P粉642436282

    P粉6424362822023-08-22 10:24:30

    I’m not sure about browser compatibility

    word-break: break-all;
    

    You can also use the <wbr> tag

    reply
    0
  • P粉864594965

    P粉8645949652023-08-22 09:39:19

    Useword-wrap:break-word;

    This works even in IE6, which is a pleasant surprise.


    word-wrap: break-word has been replaced by overflow-wrap: break-word;, which works in all modern browsers. Since IE is an outdated browser, it will always rely on the deprecated and non-standard word-wrap.

    The current case of using word-wrap will still work fine as it is an alias for the canonical overflow-wrap.

    reply
    0
  • Cancelreply