--- title: height slug: Web/CSS/height translation_of: Web/CSS/height ---
高度(height) 的 CSS 屬性指定了元素內容區域的高度。content area 在元素的留白(padding)、邊框(border) 與 邊界(margin) 內。
{{cssxref("min-height")}} 與 {{cssxref("max-height")}} 的特性比 {{Cssxref("height")}} 更重要。
{{cssinfo}}
/* Keyword value */ height: auto; /* <length> values */ height: 120px; height: 10em; /* <percentage> value */ height: 75%; /* Global values */ height: inherit; height: initial; height: unset;
<length><percentage>auto。用在 root 元素 (e.g. <html>) 上是相對於初始塊狀元素(即顯示器的尺寸)。border-box {{experimental_inline}}content-box {{experimental_inline}}autofill-available inline size or fill-available block size, as appropriate to the writing mode.max-content {{experimental_inline}}min-content {{experimental_inline}}available {{experimental_inline}}fit-content {{experimental_inline}}<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>
div {
width: 250px;
margin-bottom: 5px;
border: 3px solid #999999;
}
#red {
height: 50px;
}
#green {
height: 25px;
}
#parent {
height: 100px;
}
#child {
height: 50%;
width: 75%;
}
{{EmbedLiveSample('Example')}}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('CSS3 Box', '#the-width-and-height-properties', 'height')}} | {{Spec2('CSS3 Box')}} | Added the max-content, min-content, available, fit-content, border-box, content-box keywords. |
| {{SpecName('CSS3 Transitions', '#animatable-css', 'height')}} | {{Spec2('CSS3 Transitions')}} | Lists height as animatable. |
| {{SpecName('CSS2.1', 'visudet.html#the-height-property', 'height')}} | {{Spec2('CSS2.1')}} | Adds support for the {{cssxref("<length>")}} values and precises on which element it applies to. |
| {{SpecName('CSS1', '#height', 'height')}} | {{Spec2('CSS1')}} | Initial definition |
| {{SpecName('CSS3 Sizing', '#width-height-keywords', 'width')}} | {{Spec2('CSS3 Sizing')}} | Adds new sizing keywords for width and height. |