1、定义与属性
1.1、word-wrap
允许长单词换行到下一行
语法
word-wrap: normal|break-word;
1.2、word-break
在恰当的断字点进行换行
语法
word-break: normal|break-all|keep-all;
2、案例分析
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>断句</title><style type="text/css">.text1{width: 120px;height: 100px;background-color: gray;word-wrap: break-word;}.text2{width: 120px;height: 100px;background-color: red;word-break: break-all;}</style></head><body><p class="text1">There is no royal road to learning.</p><p class="text2">There is no royal road to learning.</p></body></html>
此时,使用word-wrap: break-word;
为了防止长单词溢出,就在它的内部断句了。
使用word-break: break-all;
不会尝试把长单词挪到下一行,而是直接进行单词内的断句。