How to implement forced line wrapping of long words in DIV?
P粉450744515
P粉450744515 2023-08-21 14:03:56
0
2
346
<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粉450744515
P粉450744515

reply all(2)
P粉642436282

I’m not sure about browser compatibility

word-break: break-all;

You can also use the <wbr> tag

P粉864594965

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!