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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
---
title: height
slug: Web/CSS/height
translation_of: Web/CSS/height
---
<div>{{CSSRef}}</div>
<h2 id="概要">概要</h2>
<p><strong><code>高度(height)</code></strong> 的 CSS 屬性指定了元素內容區域的高度。<a href="/en-US/docs/CSS/box_model#content">content area</a> 在元素的留白(padding)、邊框(border) 與 邊界(margin) 內。</p>
<p>{{cssxref("min-height")}} 與 {{cssxref("max-height")}} 的特性比 {{Cssxref("height")}} 更重要。</p>
<p>{{cssinfo}}</p>
<h2 id="語法">語法</h2>
<pre class="brush:css">/* Keyword value */
height: auto;
/* <length> values */
height: 120px;
height: 10em;
/* <percentage> value */
height: 75%;
/* Global values */
height: inherit;
height: initial;
height: unset;
</pre>
<h3 id="值">值</h3>
<dl>
<dt><code><length></code></dt>
<dd>查看 {{cssxref("<length>")}} 可用的單位。</dd>
<dt><code><percentage></code></dt>
<dd>{{cssxref("<percentage>")}} 相對於元素的塊狀高度。如果沒有指定塊狀元素的高度,預設值為 <code>auto。</code>用在 root 元素 (e.g. <code><html></code>) 上是相對於初始塊狀元素(即顯示器的尺寸)。</dd>
<dt><code>border-box </code>{{experimental_inline}}</dt>
<dd>If present, the preceding {{cssxref("<length>")}} or {{cssxref("<percentage>")}} is applied to the element's border box.</dd>
<dt><code>content-box</code> {{experimental_inline}}</dt>
<dd>{{cssxref("<length>")}} 或 {{cssxref("<percentage>")}} 是應用於元素的 content box.</dd>
<dt><code>auto</code></dt>
<dd>瀏覽器將計算並選擇指定元素的高度。</dd>
<dt>fill {{experimental_inline}}</dt>
<dd>Use the <code>fill-available</code> inline size or <code>fill-available</code> block size, as appropriate to the writing mode.</dd>
<dt><code>max-content</code> {{experimental_inline}}</dt>
<dd>The intrinsic preferred height.</dd>
<dt><code>min-content</code> {{experimental_inline}}</dt>
<dd>The intrinsic minimum height.</dd>
<dt><code>available</code> {{experimental_inline}}</dt>
<dd>The containing block height minus vertical margin, border and padding.</dd>
<dt><code>fit-content</code> {{experimental_inline}}</dt>
<dd>The larger of:
<ul>
<li>the intrinsic minimum height</li>
<li>the smaller of the intrinsic preferred height and the available height</li>
</ul>
</dd>
</dl>
<h3 id="正式語法">正式語法</h3>
{{csssyntax}}
<h2 id="範例">範例</h2>
<h3 id="HTML">HTML</h3>
<pre class="brush: html"><div id="red">
<span>I'm 50 pixels tall.</span>
</div>
<div id="green">
<span>I'm 25 pixels tall.</span>
</div>
<div id="parent">
<div id="child">
<span>I'm half the height of my parent.</span>
</div>
</div>
</pre>
<h3 id="CSS">CSS</h3>
<pre class="brush: css">div {
width: 250px;
margin-bottom: 5px;
border: 3px solid #999999;
}
#red {
height: 50px;
}
#green {
height: 25px;
}
#parent {
height: 100px;
}
#child {
height: 50%;
width: 75%;
}
</pre>
<p>{{EmbedLiveSample('Example')}}</p>
<h2 id="規格">規格</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 Box', '#the-width-and-height-properties', 'height')}}</td>
<td>{{Spec2('CSS3 Box')}}</td>
<td>Added the <code>max-content</code>, <code>min-content</code>, <code>available</code>, <code>fit-content</code>, <code>border-box</code>, <code>content-box</code> keywords.</td>
</tr>
<tr>
<td>{{SpecName('CSS3 Transitions', '#animatable-css', 'height')}}</td>
<td>{{Spec2('CSS3 Transitions')}}</td>
<td>Lists <code>height</code> as animatable.</td>
</tr>
<tr>
<td>{{SpecName('CSS2.1', 'visudet.html#the-height-property', 'height')}}</td>
<td>{{Spec2('CSS2.1')}}</td>
<td>Adds support for the {{cssxref("<length>")}} values and precises on which element it applies to.</td>
</tr>
<tr>
<td>{{SpecName('CSS1', '#height', 'height')}}</td>
<td>{{Spec2('CSS1')}}</td>
<td>Initial definition</td>
</tr>
<tr>
<td>{{SpecName('CSS3 Sizing', '#width-height-keywords', 'width')}}</td>
<td>{{Spec2('CSS3 Sizing')}}</td>
<td>Adds new sizing keywords for width and height.</td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器兼容性">瀏覽器兼容性</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>1.0</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop("1")}}</td>
<td>4.0</td>
<td>7.0</td>
<td>1.0</td>
</tr>
<tr>
<td><code>fill</code>, <code>fit-content</code>, <code>min-content</code>, <code>max-content</code></td>
<td>{{CompatChrome(46.0)}}</td>
<td>{{CompatUnknown}}</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Android Webview</th>
<th>Edge</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
<th>Chrome for Android</th>
</tr>
<tr>
<td>Basic support</td>
<td>1.0</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoMobile("1")}}</td>
<td>6.0</td>
<td>6.0</td>
<td>1.0</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td><code>fill</code>, <code>fit-content</code>, <code>min-content</code>, <code>max-content</code></td>
<td>{{CompatUnknown}}</td>
<td>{{CompatChrome(46.0)}}</td>
<td>{{CompatUnknown}}</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>{{CompatChrome(46.0)}}</td>
</tr>
</tbody>
</table>
</div>
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/CSS/box_model">box model</a>, {{cssxref("width")}}, {{cssxref("box-sizing")}}, {{cssxref("min-height")}}, {{cssxref("max-height")}}</li>
</ul>
|