height
CSS property specifies the height of an element. By default, the property defines the height of the
content area
。若
box-sizing
is set to
border-box
, however, it instead determines the height of the
border area
.
min-height
and
max-height
properties override
height
.
/* Keyword value */ height: auto; /* <length> values */ height: 120px; height: 10em; /* <percentage> value */ height: 75%; /* Global values */ height: inherit; height: initial; height: unset;
<length>
Defines the height as an absolute value.
<percentage>
Defines the height as a percentage of the containing block's height.
auto
The browser will calculate and select a height for the specified element.
max-content
The intrinsic preferred height.
min-content
The intrinsic minimum height.
fit-content(
<length-percentage>
)
Uses the fit-content formula with the available space replaced by the specified argument, i.e. min(max-content, max(min-content, )).
Ensure that elements set with a
height
are not truncated and/or do not obscure other content when the page is zoomed to increase text size.
| 初始值 |
auto
|
|---|---|
| 适用于 | all elements but non-replaced inline elements, table columns, and column groups |
| 继承 | no |
| 百分比 |
The percentage is calculated with respect to the height of the generated box's containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to
auto
. A percentage height on the root element is relative to the initial containing block.
|
| 计算值 |
a percentage or
auto
or the absolute length
|
| 动画类型 | a length , percentage or calc(); |
auto | <length> | <percentage> | min-content | max-content | fit-content(<length-percentage>)where
<length-percentage> = <length> | <percentage>
<div id="taller">I'm 50 pixels tall.</div>
<div id="shorter">I'm 25 pixels tall.</div>
<div id="parent">
<div id="child">
I'm half the height of my parent.
</div>
</div>
div {
width: 250px;
margin-bottom: 5px;
border: 2px solid blue;
}
#taller {
height: 50px;
}
#shorter {
height: 25px;
}
#parent {
height: 100px;
}
#child {
height: 50%;
width: 75%;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Box Sizing Module Level 4
The definition of 'height' in that specification. |
编者草案 | |
|
CSS Box Sizing Module Level 3
The definition of 'height' in that specification. |
工作草案 |
添加
max-content
,
min-content
,
fit-content
keywords.
|
|
CSS Level 2 (Revision 1)
The definition of 'height' in that specification. |
推荐 |
Adds support for the
<length>
values and precises on which element it applies to.
|
|
CSS Level 1
The definition of 'height' in that specification. |
推荐 | 初始定义。 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
height
|
Chrome 完整支持 1 | Edge 完整支持 12 | Firefox 完整支持 1 | IE 完整支持 4 | Opera 完整支持 7 | Safari 完整支持 1 | WebView Android 完整支持 1 | Chrome Android 完整支持 18 | Firefox Android 完整支持 4 | Opera Android 完整支持 10.1 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
fit-content
|
Chrome 完整支持 46 | Edge 完整支持 79 | Firefox 不支持 No | IE 不支持 No | Opera 完整支持 33 | Safari 完整支持 11 | WebView Android 完整支持 46 | Chrome Android 完整支持 46 | Firefox Android 不支持 No | Opera Android 完整支持 33 | Safari iOS 完整支持 11 | Samsung Internet Android 完整支持 5.0 |
max-content
|
Chrome 完整支持 46 | Edge 完整支持 79 |
Firefox
完整支持
66
|
IE 不支持 No | Opera 完整支持 44 | Safari 完整支持 11 | WebView Android 完整支持 46 | Chrome Android 完整支持 46 |
Firefox Android
完整支持
66
|
Opera Android 完整支持 43 | Safari iOS 完整支持 11 | Samsung Internet Android 完整支持 5.0 |
min-content
|
Chrome 完整支持 46 | Edge 完整支持 79 |
Firefox
完整支持
66
|
IE 不支持 No | Opera 完整支持 44 | Safari 完整支持 11 | WebView Android 完整支持 46 | Chrome Android 完整支持 46 |
Firefox Android
完整支持
66
|
Opera Android 完整支持 43 | Safari iOS 完整支持 11 | Samsung Internet Android 完整支持 5.0 |
stretch
|
Chrome
完整支持
28
Alternate Name
|
Edge
完整支持
79
Alternate Name
|
Firefox 不支持 No | IE 不支持 No |
Opera
完整支持
15
Alternate Name
|
Safari
完整支持
9
Alternate Name
|
WebView Android
完整支持
4.4
Alternate Name
|
Chrome Android
完整支持
28
Alternate Name
|
Firefox Android 不支持 No |
Opera Android
完整支持
15
Alternate Name
|
Safari iOS
完整支持
9
Alternate Name
|
Samsung Internet Android
完整支持
5.0
Alternate Name
|
完整支持
不支持
使用非标名称。
要求使用供应商前缀或不同名称。
box-sizing
max-height
,
min-height
block-size
,
inline-size
height
margin-bottom
margin-left
margin-right
margin-top
margin-trim
max-height
max-width
min-height
min-width
overscroll-behavior
overscroll-behavior-block
overscroll-behavior-inline
overscroll-behavior-x
overscroll-behavior-y
padding
padding-bottom
padding-left
padding-right
padding-top
visibility
width