Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

max-height

概述

max-height 这个属性会阻止 height 属性的设置值变得比 max-height 更大。

max-height 属性用来设置给定元素的最大高度. 如果height 属性设置的高度比该属性设置的高度还大,则height 属性会失效.

max-height 重载(覆盖掉) height, 但是 min-height 又会重载(覆盖掉) max-height.

初始值none
适用元素all elements but non-replaced inline elements, table columns, and column groups
是否是继承属性
PercentagesThe 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 percentage value is treated as none.
适用媒体visual
计算值the percentage as specified or the absolute length or none
是否适用于 CSS 动画yes, as a length, percentage or calc(); when both values are lengths, they are interpolated as lengths; when both values are percentages, they are interpolated as percentages; otherwise, both values are converted into a calc() function that is the sum of a length and a percentage (each possibly zero), and these calc() functions have each half interpolated as real numbers.
正规顺序the unique non-ambiguous order defined by the formal grammar

语法

/* <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;
max-height: fill-available;

max-height: inherit;

 

<length>
一个固定的最大高度. 查看<length>了解可用的长度单位.
<percentage>
<percentage>值是根据包含该元素的父元素的高度计算得来的,如果该元素的父元素没有明确的指定高度,则该百分比相当于none.
none
不限制高度.
<length>
A fixed maximum height. See <length> for possible units.
<percentage>
The <percentage> is calculated with respect to the height of the containing block. If the height of the containing block is not specified explicitly, the percentage value is treated as none.
none
No limit on the height of the box.
max-content
The intrinsic preferred height.
min-content
The intrinsic minimum height.
fill-available
The containing block height minus vertical margin, border and padding. Some browsers implement an ancient name for this keyword, available.
fit-content

The same as max-content. 

正规语法

<length> | <percentage> | none | max-content | min-content | fit-content | fill-available

 

例子

table { max-height: 75%; }

form { max-height: none; }

 

查看在线演示

Specifications

Specification Status Comment
CSS Intrinsic & Extrinsic Sizing Module Level 3
max-height
Working Draft Adds the max-content,min-contentfit-content, and fill-available keywords.
Both CSS3 Box and CSS3 Writing Modes drafts defined at some point these keywords. These drafts are superseded by this spec.
CSS Transitions
max-height
Working Draft Defines max-height as animatable.
CSS Level 2 (Revision 1)
max-height
Recommendation Initial definition.

 

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) 7.0 7.0 1.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 1.0 (1) 6.0 6.0 1.0

 

[1] CSS 2.1 explicitely leaves the behavior of max-height with <table> undefined. Therefore any behavior is CSS2.1-compliant; newer CSS specifications may define this behavior, so Web developers shouldn't rely on a specific one now.

[2] Gecko experimentally implements the definitions given in CSS3 Basic Box. This one defines available and not fill-available. Also the definition of fit-content is simpler than in CSS3 Sizing.

[3] WebKit implements an earlier proposal for setting the height to an intrinsic height: the keywords intrinsic, instead of max-content, and min-intrinsic, instead of min-content. There is no equivalent for fill-available or fit-content.

参见

文档标签和贡献者

 此页面的贡献者: Sebastianz, fscholz, FredWe, teoli, ziyunfei
 最后编辑者: Sebastianz,