--- title: hyphens slug: Web/CSS/hyphens translation_of: Web/CSS/hyphens ---
CSS 属性 hyphens
告知浏览器在换行时如何使用连字符连接单词。可以完全阻止使用连字符,也可以控制浏览器什么时候使用,或者让浏览器决定什么时候使用。
连字规则具有语言特定性。在 HTML 中,语言由 lang 属性决定,浏览器只会在当前属性存在且有合适的连字字典可用的情况使用连字进行连接。 在 XML 中,必须使用 xml:lang
属性。
{{cssinfo}}
hyphens: none; hyphens: manual; hyphens: auto; /* Global values */ hyphens: inherit; hyphens: initial; hyphens: unset;
none
manual
auto
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.There are two Unicode characters that can be used to manually specify potential line break points within text:
­
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; }
{{EmbedLiveSample("Example", "100%", "470'")}}
Specification | Status | Comment |
---|---|---|
{{SpecName("CSS3 Text", "#hyphens-property", "hyphens")}} | {{Spec2("CSS3 Text")}} | Initial definition |