max-height
CSS属性 max-height 设置元素的最大高度。它防止
height
属性的使用值大于
max-height
的指定值。
max-height
会覆盖
height
,而
min-height
会覆盖
max-height
。
示例
/* <length> value */
max-height: 3.5em;
/* <percentage> value */
max-height: 75%;
/* Keyword values */
max-height: none;
max-height: max-content;
max-height: min-content;
max-height: fit-content(20em);
/* Global values */
max-height: inherit;
max-height: initial;
max-height: unset;
浏览器支持
语法
max-height
:
auto
|
<length>
|
<percentage>
|
min-content
|
max-content
|
fit-content()
取值:
-
auto
:浏览器将计算并选择指定图元的最大高度。
-
<length>
:将最大高度定义为绝对值。参见
<length>
。
-
<percentage>
:将最大高度定义为包含块高度的百分比。必须是非负的。参见
<percentage>
。
-
max-content
:固有的最大高度。
-
min-content
:固有的最小高度。
-
fit-content()
:将可用空间替换为指定参数,即 min(max-content, max(min-content, argument))。
默认值
|
auto
|
适用于
|
除非置换内联元素,table-row, table-row-group之外的所有元素
|
继承性
|
无
|
动画性
|
否
|
计算值
|
如果指定为长度,则为相应的绝对长度;如果指定为百分比,则为指定值;否则为auto
|
例子
table { max-height: 75%; }
form { max-height: none; }