CSS

连字符 | hyphens

hyphens

hyphens CSS属性指定当文字跨越多行时如何自动换行断字。您可以完全禁止连字符,在文本中手动指定点来使用连字符,或者让浏览器在适当的地方自动插入连字符。

/* Keyword values */ hyphens: none; hyphens: manual; hyphens: auto; /* Global values */ hyphens: inherit; hyphens: initial; hyphens: unset;

连字规则是依语言而定的。在HTML中,语言是由lang属性决定的,只有当这个属性存在时且有合适的连字符字典可用时,浏览器才会使用连字符。在XML中,要求必须使用xml:lang属性。

注意:定义如何执行连字符的规则没有被规范明确定义,所以确切的连字符规则可能因浏览器而异。

Initial valuemanual
Applies toall elements
Inheritedyes
Mediavisual
Computed valueas specified
Animation typediscrete
Canonical orderthe unique non-ambiguous order defined by the formal grammar

语法

hyphens属性被指定为从下面的列表中选择出的单个关键字。

可能值

none——即使文字中的字符表示换行符,文字也不会在换行符处断开。行将只包含在空白处。

注:auto设置的行为取决于语言被正确标记,以便可以选择相应的断字规则。您必须使用lang这个HTML属性指定一种语言,以确保自动连字符应用于您所选择的语言。

建议换行时机

有两个Unicode字符可用于在文本中手动指定潜在的换行点:

U + 2010(HYPHEN):该“硬”连字符表示可见的换行时机。即使该行实际上没有被断开,连字符仍然呈现。

形式语法

none | manual | auto

实例

这个例子使用三个类,其中一个用于hyphens属性的每个可能的配置。

HTML

<ul> <li><code>none</code>: no hyphen; overflow if needed <p lang="en" class="none">An extreme&shy;ly long English word</p> </li> <li><code>manual</code>: hyphen only at &amp;hyphen; or &amp;shy; (if needed) <p lang="en" class="manual">An extreme&shy;ly long English word</p> </li> <li><code>auto</code>: hyphen where the algorithm is deciding (if needed) <p lang="en" class="auto">An extreme&shy;ly long English word</p> </li> </ul>

CSS

p { width: 55px; border: 1px solid black; } p.none { -webkit-hyphens: none; -ms-hyphens: none; hyphens: none; } p.manual { -webkit-hyphens: manual; -ms-hyphens: manual; hyphens: manual; } p.auto { -webkit-hyphens: auto; -ms-hyphens: auto; hyphens: auto; }

结果

规范

SpecificationStatusComment
CSS Text Module Level 3The definition of 'hyphens' in that specification.Working DraftInitial definition

浏览器兼容性

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support13.0-webkit1 55.0 (unprefixed)6.0 (6.0)-moz2 43.0 (43.0)10.0-ms3445.1-webkit
Hyphenation dictionary for Afrikaans (af, af-*)?8.0 (8.0)No support?No support
Hyphenation dictionary for Bulgarian (bg, bg-*)?8.0 (8.0)No support?No support
Hyphenation dictionary for Catalan (ca, ca-*)?8.0 (8.0)10.0?9.1
Hyphenation dictionary for Croatian (hr, hr-*)?8.0 (8.0)No support?9.1
Hyphenation dictionary for Czech (cs, cs-*)?No support10.0?9.1
Hyphenation dictionary for Danish (da, da-*)?8.0 (8.0)10.0?9.1
Hyphenation dictionary for Dutch (nl, nl-*)?8.0 (8.0)10.0?5.1
Hyphenation dictionary for English (en, en-*)55.0 (unprefixed)6.0 (6.0)410.0445.15
Hyphenation dictionary for Esperanto (eo, eo-*)?8.0 (8.0)No support?No support
Hyphenation dictionary for Estonian (et, et-*)?8.0 (8.0)No support?No support
Hyphenation dictionary for Finnish (fi, fi-*)?8.0 (8.0)No support?9.1
Hyphenation dictionary for French (fr, fr-*)?8.0 (8.0)10.0?5.1
Hyphenation dictionary for Galician (gl, gl-*)?9.0No support?No support
Hyphenation dictionary for German, Traditional Orthography of 1901 (de-1901, de-AT-1901, de-DE-1901)?8.0???
Hyphenation dictionary for German, Reformed Orthography of 1996 (de, de-1996, de-DE, de-AT, de-*)?8.010.0?5.1
Hyphenation dictionary for German, Swiss Orthography (de-CH, de-CH-*)?8.0???
Hyphenation dictionary for Hungarian (hu, hu-*)?9.0No support?9.1
Hyphenation dictionary for Icelandic (is, is-*)?8.0No support?No support
Hyphenation dictionary for Interlingua (ia, ia-*)?8.0No support?No support
Hyphenation dictionary for Italian (it, it-*)?9.010.0?5.1
Hyphenation dictionary for Kurmanji (kmr, kmr-*)?8.0No support?No support
Hyphenation dictionary for Latin (la, la-*)(Yes)8.0No support44No support
Hyphenation dictionary for Lithuanian (lt, lt-*)?8.0No support?No support
Hyphenation dictionary for Mongolian (mn, mn-*)?8.0No support?No support
Hyphenation dictionary for Norwegian (Bokmål) (no, no-*, nb, nb-*)?8.010.0?9.1
Hyphenation dictionary for Norwegian (Nynorsk) (nn, nn-*)?8.010.0?No support
Hyphenation dictionary for Polish (pl, pl-*)?31.010.0?9.1
Hyphenation dictionary for Portuguese (pt, pt-*)?8.0610.0?9.1
Hyphenation dictionary for Brazilian Portuguese (pt-BR)?8.0610.0?No support
Hyphenation dictionary for Russian (ru, ru-*)?8.010.0?5.1
Hyphenation dictionary for Serbian, Bosnian, Serbo-Croatian (sh, sh-*, sr, sr-*, bs, bs-*)?8.0No support?No support
Hyphenation dictionary for Slovenian (sl, sl-*)?8.0No support?No support
Hyphenation dictionary for Spanish (es, es-*)?8.010.0?5.1
Hyphenation dictionary for Swedish (sv, sv-*)?8.010.0?9.1
Hyphenation dictionary for Turkish (tr, tr-*)?9.010.0?9.1
Hyphenation dictionary for Ukrainian (uk, uk-*)?9.0No support?9.1
Hyphenation dictionary for Upper Sorbian (hsb, hsb-*)?8.0No support?No support
Hyphenation dictionary for Welsh (cy, cy-*)?8.0No support?No support
Hyphenation dictionary for other languages?No supportNo support?No support

FeatureAndroidAndroid WebviewFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome for Android
Basic support4.0-webkit155.0 (unprefixed)6.0 (6.0)-moz2 43.0 (43.0)No support444.2-webkit55.0 (unprefixed)
Hyphenation dictionary for Afrikaans (af, af-*)???????
Hyphenation dictionary for Bulgarian (bg, bg-*)???????
Hyphenation dictionary for Catalan (ca, ca-*)???????
Hyphenation dictionary for Croatian (hr, hr-*)???????
Hyphenation dictionary for Czech (cs, cs-*)???????
Hyphenation dictionary for Danish (da, da-*)???????
Hyphenation dictionary for Dutch (nl, nl-*)???????
Hyphenation dictionary for English (en, en-*)?55.0 (unprefixed)??44?55.0 (unprefixed)
Hyphenation dictionary for Esperanto (eo, eo-*)???????
Hyphenation dictionary for Estonian (et, et-*)???????
Hyphenation dictionary for Finnish (fi, fi-*)???????
Hyphenation dictionary for French (fr, fr-*)???????
Hyphenation dictionary for Galician (gl, gl-*)???????
Hyphenation dictionary for German, Traditional Orthography of 1901 (de-1901, de-AT-1901, de-DE-1901)???????
Hyphenation dictionary for German, Reformed Orthography of 1996 (de, de-1996, de-DE, de-AT, de-*)???????
Hyphenation dictionary for German, Swiss Orthography (de-CH, de-CH-*)???????
Hyphenation dictionary for Hungarian (hu, hu-*)???????
Hyphenation dictionary for Icelandic (is, is-*)???????
Hyphenation dictionary for Interlingua (ia, ia-*)???????
Hyphenation dictionary for Italian (it, it-*)???????
Hyphenation dictionary for Kurmanji (kmr, kmr-*)???????
Hyphenation dictionary for Latin (la, la-*)?(Yes)??44?(Yes)
Hyphenation dictionary for Lithuanian (lt, lt-*)???????
Hyphenation dictionary for Mongolian (mn, mn-*)???????
Hyphenation dictionary for Norwegian (Bokmål) (no, no-*, nb, nb-*)???????
Hyphenation dictionary for Norwegian (Nynorsk) (nn, nn-*)???????
Hyphenation dictionary for Polish (pl, pl-*)???????
Hyphenation dictionary for Portuguese (pt, pt-*)???????
Hyphenation dictionary for Brazilian Portuguese (pt-BR)??????
Hyphenation dictionary for Russian (ru, ru-*)???????
Hyphenation dictionary for Serbian, Bosnian, Serbo-Croatian (sh, sh-*, sr, sr-*, bs, bs-*)???????
Hyphenation dictionary for Slovenian (sl, sl-*)???????
Hyphenation dictionary for Spanish (es, es-*)???????
Hyphenation dictionary for Swedish (sv, sv-*)???????
Hyphenation dictionary for Turkish (tr, tr-*)???????
Hyphenation dictionary for Ukrainian (uk, uk-*)???????
Hyphenation dictionary for Upper Sorbian (hsb, hsb-*)???????
Hyphenation dictionary for Welsh (cy, cy-*)???????
Hyphenation dictionary for other languages???????