blob: 7a09198e887ab886eaae5b3237714545ea797091 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
---
title: hyphens
slug: Web/CSS/hyphens
translation_of: Web/CSS/hyphens
---
<div>{{CSSRef}}</div>
<h2 id="Summary">Summary</h2>
<p><a href="/en-US/docs/CSS">CSS</a> 属性 <strong><code>hyphens</code></strong> 告知浏览器在换行时如何使用连字符连接单词。可以完全阻止使用连字符,也可以控制浏览器什么时候使用,或者让浏览器决定什么时候使用。</p>
<p>连字规则具有语言特定性。在 HTML 中,语言由 lang 属性决定,浏览器只会在当前属性存在且有合适的连字字典可用的情况使用连字进行连接。 在 XML 中,必须使用 <code>xml:lang</code> 属性。</p>
<div class="note"><strong>注意:</strong>:在规范中,没有明确定义连字符的实现规则,所以具体的连字符在不同浏览器中可能有所区别。</div>
<p>{{cssinfo}}</p>
<h2 id="语法">语法</h2>
<pre class="brush:css">hyphens: none;
hyphens: manual;
hyphens: auto;
/* Global values */
hyphens: inherit;
hyphens: initial;
hyphens: unset;
</pre>
<h3 id="值">值</h3>
<dl>
<dt><code>none</code></dt>
<dd>换行时单词不会被打断,甚至在单词内的字符建议有换行点时。行只会在空白符处换行。</dd>
<dt><code>manual</code></dt>
<dd>Words are broken for line-wrapping only where characters inside the word suggest line break opportunities. See {{anch("Suggesting line break opportunities")}} for details.</dd>
<dt><code>auto</code></dt>
<dd>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 {{anch("Suggesting line break opportunities")}}, should be preferred over automatically selecting break points whenever possible.</dd>
</dl>
<div class="note"><strong>Note:</strong> The <code>auto</code> 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 <code>lang</code> HTML attribute in order to guarantee that automatic hyphenation is applied in the language of your choice.</div>
<h2 id="Suggesting_line_break_opportunities">Suggesting line break opportunities</h2>
<p>There are two Unicode characters that can be used to manually specify potential line break points within text:</p>
<dl>
<dt>U+2010 (HYPHEN)</dt>
<dd>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.</dd>
<dt>U+00AD (SHY)</dt>
<dd>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 <code>&shy;</code> to insert a soft hyphen.</dd>
</dl>
<h3 id="Formal_syntax">Formal syntax</h3>
{{csssyntax}}
<h2 id="示例">示例</h2>
<p>以下代码段展示了<code>hyphens</code>属性取none/manual/auto这三类值的效果。</p>
<pre class="brush: 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 algo is deciding (if needed)
<p lang="en" class="auto">An extreme&shy;ly long English word</p>
</li>
</ul>
</pre>
<pre class="brush: 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;
}
</pre>
<figure>
<p>{{EmbedLiveSample("Example", "100%", "470'")}}</p>
</figure>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("CSS3 Text", "#hyphens-property", "hyphens")}}</td>
<td>{{Spec2("CSS3 Text")}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
{{Compat("css.properties.hyphens")}}
<h2 id="See_also">See also</h2>
<ul>
<li>{{Cssxref("content")}}</li>
</ul>
|