hyphens - CSS(层叠样式表) 编辑

Summary

CSS 属性 hyphens 告知浏览器在换行时如何使用连字符连接单词。可以完全阻止使用连字符,也可以控制浏览器什么时候使用,或者让浏览器决定什么时候使用。

连字规则具有语言特定性。在 HTML 中,语言由 lang 属性决定,浏览器只会在当前属性存在且有合适的连字字典可用的情况使用连字进行连接。 在 XML 中,必须使用 xml:lang 属性。

注意::在规范中,没有明确定义连字符的实现规则,所以具体的连字符在不同浏览器中可能有所区别。
初始值manual
适用元素all elements
是否是继承属性yes
适用媒体visual
计算值as specified
Animation typediscrete
正规顺序the unique non-ambiguous order defined by the formal grammar

语法

hyphens: none;
hyphens: manual;
hyphens: auto;

/* Global values */
hyphens: inherit;
hyphens: initial;
hyphens: unset;

none
换行时单词不会被打断,甚至在单词内的字符建议有换行点时。行只会在空白符处换行。
manual
Words are broken for line-wrapping only where characters inside the word suggest line break opportunities. See Suggesting line break opportunities for details.
auto
The browser is free to automatically break words at appropriate hyphenation points, following whatever rules it chooses to use. Suggested line break opportunities, as covered in Suggesting line break opportunities, should be preferred over automatically selecting break points whenever possible.
Note: The auto setting's behavior depends on the language being properly tagged so that the appropriate hyphenation rules can be selected. You must specify a language using the lang HTML attribute in order to guarantee that automatic hyphenation is applied in the language of your choice.

Suggesting line break opportunities

There are two Unicode characters that can be used to manually specify potential line break points within text:

U+2010 (HYPHEN)
The "hard" hyphen character indicates a visible line break opportunity. Even if the line is not actually broken at that point, the hyphen is still rendered.
U+00AD (SHY)
An invisible, "soft" hyphen. This character is not rendered visibly; instead, it suggests a place where the browser might choose to break the word if necessary. In HTML, you can use ­ to insert a soft hyphen.

Formal syntax

none | manual | auto

示例

以下代码段展示了hyphens属性取none/manual/auto这三类值的效果。

<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 algo is deciding (if needed)
    <p lang="en" class="auto">An extreme&shy;ly long English word</p>
  </li>
</ul>
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;
}

Specifications

SpecificationStatusComment
CSS Text Module Level 3
hyphens
Working DraftInitial definition

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support13-webkit[1]

6.0 (6.0)-moz[2]
43.0 (43.0)

10.0-ms[3]未实现5.1-webkit
Hyphenation dictionary for Afrikaans (af, af-*)未实现8.0 (8.0)未实现未实现未实现
Hyphenation dictionary for Bulgarian (bg, bg-*)未实现8.0 (8.0)未实现未实现未实现
Hyphenation dictionary for Catalan (ca, ca-*)未实现8.0 (8.0)10.0未实现未实现
Hyphenation dictionary for Croatian (hr, hr-*)未实现8.0 (8.0)未实现未实现未实现
Hyphenation dictionary for Czech (cs, cs-*)未实现未实现10.0未实现未实现
Hyphenation dictionary for Danish (da, da-*)未实现8.0 (8.0)10.0未实现未实现
Hyphenation dictionary for Dutch (nl, nl-*)未实现8.0 (8.0)10.0未实现5.1
Hyphenation dictionary for English (en, en-*)未实现6.0 (6.0)[4]10.0未实现5.1[5]
Hyphenation dictionary for Esperanto (eo, eo-*)未实现8.0 (8.0)未实现未实现未实现
Hyphenation dictionary for Estonian (et, et-*)未实现8.0 (8.0)未实现未实现未实现
Hyphenation dictionary for Finnish (fi, fi-*)未实现8.0 (8.0)未实现未实现未实现
Hyphenation dictionary for French (fr, fr-*)未实现8.0 (8.0)10.0未实现5.1
Hyphenation dictionary for Galician (gl, gl-*)未实现9.0未实现未实现未实现
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.0未实现未实现未实现
Hyphenation dictionary for Icelandic (is, is-*)未实现8.0未实现未实现未实现
Hyphenation dictionary for Interlingua (ia, ia-*)未实现8.0未实现未实现未实现
Hyphenation dictionary for Italian (it, it-*)未实现9.010.0未实现5.1
Hyphenation dictionary for Kurmanji (kmr, kmr-*)未实现8.0未实现未实现未实现
Hyphenation dictionary for Latin (la, la-*)未实现8.0未实现未实现未实现
Hyphenation dictionary for Lithuanian (lt, lt-*)未实现8.0未实现未实现未实现
Hyphenation dictionary for Mongolian (mn, mn-*)未实现8.0未实现未实现未实现
Hyphenation dictionary for Norwegian (Bokmål) (no, no-*, nb, nb-*)未实现8.010.0未实现未实现
Hyphenation dictionary for Norwegian (Nynorsk) (nn, nn-*)未实现8.010.0未实现未实现
Hyphenation dictionary for Polish (pl, pl-*)未实现31.010.0未实现未实现
Hyphenation dictionary for Portuguese (pt, pt-*)未实现8.0[6]10.0未实现未实现
Hyphenation dictionary for Brazilian Portuguese (pt-BR)未实现8.0[6]10.0未实现未实现
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.0未实现未实现未实现
Hyphenation dictionary for Slovenian (sl, sl-*)未实现8.0未实现未实现未实现
Hyphenation dictionary for Spanish (es, es-*)未实现8.010.0未实现5.1
Hyphenation dictionary for Swedish (sv, sv-*)未实现8.010.0未实现未实现
Hyphenation dictionary for Turkish (tr, tr-*)未实现9.010.0未实现未实现
Hyphenation dictionary for Ukrainian (uk, uk-*)未实现9.0未实现未实现未实现
Hyphenation dictionary for Upper Sorbian (hsb, hsb-*)未实现8.0未实现未实现未实现
Hyphenation dictionary for Welsh (cy, cy-*)未实现8.0未实现未实现未实现
Hyphenation dictionary for other languages未实现未实现未实现未实现未实现
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support4.0-webkit[1]6.0 (6.0)-moz[2]
43.0 (43.0)
未实现未实现4.2-webkit
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-*)?????
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-*)?????
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?????

[1] No automatic hyphenation, only -webkit-hyphens: none is supported.

[2] Automatic hyphenation only works for languages whose hyphenation dictionaries are integrated in Gecko. See the note below for a complete list of such languages.

[3] Automatic hyphenation only works for languages whose hyphenation dictionaries are integrated in Internet Explorer. See the note below for a complete list of such languages.

[4] Uses an en-US dictionary.

[5] en-GB and en-US used different dictionaries.

[6] Uses a Portuguese dictionary.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:118 次

字数:22551

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文