CSS 属性 word-break 指定了怎样在单词内断行。

语法

word-break: normal 
word-break: break-all 
word-break: keep-all
word-break: break-word; /* non-standard */ 

/* Global values */
word-break: inherit;
word-break: initial;
word-break: unset;

normal
使用默认的断行规则。
break-all
对于non-CJK (CJK 指中文/日文/韩文) 文本,可在任意字符间断行。
keep-all
CJK 文本不断行。 Non-CJK 文本表现同 normal

正式语法

normal | break-all | keep-all | break-word

示例

HTML

<p>1. <code>word-break: normal</code></p>
<p class="normal narrow">This is a long and
 Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu
 グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉</p>

<p>2. <code>word-break: break-all</code></p>
<p class="breakAll narrow">This is a long and
 Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu
 グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉</p>

<p>3. <code>word-break: keep-all</code></p>
<p class="keepAll narrow">This is a long and
 Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu
 グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉</p>

<p>4. <code>word-break: break-word</code></p> 
<p class="breakWord narrow">This is a long and 
  Honorificabilitudinitatibus califragilisticexpialidocious Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu
 グレートブリテンおよび北アイルランド連合王国という言葉は本当に長い言葉</p>

CSS

.narrow {
  padding: 5px;
  border: 1px solid;
  display: table;
  max-width: 100%;
}

.normal {
  word-break: normal;
}

.breakAll {
  word-break: break-all;
}

.keepAll {
  word-break: keep-all;
}

.breakWord { 
  word-break: break-word; 
} 

规范

规范 状态 注释
CSS Text Module Level 3
word-break
Working Draft  
初始值normal
适用元素all elements
是否是继承属性yes
适用媒体visual
计算值as specified
Animation typediscrete
正规顺序the unique non-ambiguous order defined by the formal grammar

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
word-breakChrome Full support 1Edge Full support 12Firefox Full support 15IE Full support 5.5
Notes
Full support 5.5
Notes
Notes No version of Internet Explorer supports the initial value.
Full support 8
Prefixed Notes
Prefixed Implemented with the vendor prefix: -ms-
Notes Don't use -ms-word-break, which is a synonym for word-break.
Opera Full support 15Safari Full support YesWebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 15Opera Android ? Safari iOS ? Samsung Internet Android Full support Yes
keep-allChrome Full support 44Edge Full support YesFirefox Full support 15IE Full support 5.5Opera Full support 31Safari Full support 9WebView Android Full support YesChrome Android Full support YesEdge Mobile No support NoFirefox Android Full support 15Opera Android No support NoSafari iOS Full support 9Samsung Internet Android Full support Yes
break-wordChrome Full support YesEdge Full support YesFirefox No support NoIE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile No support NoFirefox Android No support NoOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

相关链接

文档标签和贡献者

标签: 
最后编辑者: mdnwebdocs-bot,