height

height CSS 属性是同时设置可视区 min-height and max-height 的简写。当你设置一个值的时候,最小高度(minimum height)和最大高度(maximum height)会被同时设置。

如果提供两个值,第一个值会被设置为最小高度,第二个值将会被设置为最大高度。

语法

/* One value */
height: auto;
height: 320px;
height: 15em;

/* Two values */
height: 320px 200px;

合法值

auto
真实生效的高度值将根据其他 CSS 属性计算得出。
<length>
一个非负的绝对或相对值。
<percentage>
一个相对于缩放因子是 1.0 的初始可视区宽高的百分比值,水平和垂直方向的长度分别计算。不能是负值。

正式定义

Related at-rule@viewport
初始值as each of the properties of the shorthand:
Percentagesas each of the properties of the shorthand:
  • min-height: 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 percentage value is treated as 0.
  • max-height: 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 percentage value is treated as none.
计算值as each of the properties of the shorthand:
  • min-height: the percentage as specified or the absolute length
  • max-height: the percentage as specified or the absolute length or none

正式语法

<viewport-length>{1,2}

where
<viewport-length> = auto | <length-percentage>

where
<length-percentage> = <length> | <percentage>

示例

设置最小和最大高度

@viewport {
  height: 500px;
}

规范

Specification Status Comment
CSS Device Adaptation
"height" descriptor
Working Draft 初始定义

同时查看