CSS
属性 word-break
指定了怎样在单词内断行。
word-break: normal;
word-break: break-all;
word-break: keep-all;
word-break: break-word;
non-CJK
(CJK 指中文/日文/韩文) 文本,可在任意字符间断行。【拆分单词】CJK
文本不断行。Non-CJK
文本表现同 normal。【英文单词不拆分,中文文本不换行】word-break: normal
和 overflow-wrap: anywhere
的合,不论 overflow-wrap
的值是多少。<p>1. <code>word-break: normalcode>p>
<p class="normal narrow">This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉p>
<p>2. <code>word-break: break-allcode>p>
<p class="breakAll narrow">This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉p>
<p>3. <code>word-break: keep-allcode>p>
<p class="keepAll narrow">This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉p>
<p>4. <code>word-break: break-wordcode>p>
<p class="breakWord narrow">This is a long and Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉p>
.narrow {
padding: 10px;
border: 1px solid;
width: 500px;
margin: 0 auto;
font-size: 20px;
line-height: 1.5;
letter-spacing: 1px;
}
.normal {
word-break: normal;
}
.breakAll {
word-break: break-all;
}
.keepAll {
word-break: keep-all;
}
.breakWord {
word-break: break-word;
}
效果如图:
CSS 属性 overflow-wrap
是用来说明当一个不能被分开的字符串太长而不能填充其包裹盒时,为防止其溢出,浏览器是否允许这样的单词中断换行。
overflow-wrap: normal;
overflow-wrap: break-word;
overflow-wrap: anywhere;
<p>They say the fishing is excellent at Lake <em class="normal">Chargoggagoggmanchauggagoggchaubunagungamauggem>, though I've never been there myself. (<code>normalcode>)p>
<p>They say the fishing is excellent at Lake <em class="ow-anywhere">Chargoggagoggmanchauggagoggchaubunagungamauggem>, though I've never been there myself. (<code>overflow-wrap: anywherecode>)p>
<p>They say the fishing is excellent at Lake <em class="ow-break-word">Chargoggagoggmanchauggagoggchaubunagungamauggem>, though I've never been there myself. (<code>overflow-wrap: break-wordcode>)p>
<p>They say the fishing is excellent at Lake <em class="word-break">Chargoggagoggmanchauggagoggchaubunagungamauggem>, though I've never been there myself. (<code>word-breakcode>)p>
p {
width: 13em;
margin: 2px;
background: gold;
}
.ow-anywhere {
overflow-wrap: anywhere;
}
.ow-break-word {
overflow-wrap: break-word;
}
.word-break {
word-break: break-all;
}
效果如图:
word-wrap
属性原本属于微软的一个私有属性,在CSS3
现在的文本规范草案中已经被重名为overflow-wrap
。word-wrap
现在被当作overflow-wrap
的“别名”。稳定的谷歌Chrome
和Opera
浏览器版本支持这种新语法。
与
word-break
相比,overflow-wrap
仅在无法将整个单词放在自己的行而不会溢出的情况下才会产生中断。
如果你感觉文章不咋地
//(ㄒoㄒ)//
,就在评论处留言,作者继续改进;o_O???
如果你觉得该文章有一点点用处,可以给作者点个赞;\\*^o^*//
如果你想要和作者一起进步,可以微信扫描二维码,关注前端老L;~~~///(^v^)\\\~~~
谢谢各位读者们啦(^_^)∠※
!!!