word-wrap:break-word;与word-break:break-all;的区别:
1)word-wrap:break-word;
<!DOCTYPE html>
<html>
<head>
<style>
p.test
{
width:11em;
border:1px solid #000000;
word-wrap:break-word;
/*word-break:break-all;*/
}
</style>
</head>
<body>
<p class="test">This paragraph contains a very long word: thisisaveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p>
</body>
</html>
运行结果:
2)word-break:break-all;
<!DOCTYPE html>
<html>
<head>
<style>
p.test
{
width:11em;
border:1px solid #000000;
/*word-wrap:break-word;*/
word-break:break-all;
}
</style>
</head>
<body>
<p class="test">This paragraph contains a very long word: thisisaveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p>
</body>
</html>
运行结果:
结论:可以看出,word-wrap:break-word;只在长单词处才断开;word-break:break-all;在所有跨行单词处断开。
代码来源:改编自https://www.w3school.com.cn/tiy/t.asp?f=eg_css3_word-wrap