hyphens
Summary
语法
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.
备注: 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.
形式语法
示例
以下代码段展示了hyphens
属性取 none/manual/auto 这三类值的效果。
<ul>
<li><code>none</code>: no hyphen; overflow if needed
<p lang="en" class="none">An extreme­ly long English word</p>
</li>
<li><code>manual</code>: hyphen only at &hyphen; or &shy; (if needed)
<p lang="en" class="manual">An extreme­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­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;
}
规范
Specification |
---|
CSS Text Module Level 3 # hyphens-property |
浏览器兼容性
BCD tables only load in the browser