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

这篇翻译不完整。请帮忙从英语翻译这篇文章

Summary

height 指定元素内容区高度。 内容区 content area 在元素padding, border, and margin 的里面。

min-height  与  max-height 覆盖 height.

初始值auto
适用元素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 value computes to auto. A percentage height on the root element is relative to the initial containing block.
适用媒体visual
计算值a percentage or auto or the absolute length
Animation typea length, percentage or calc();
正规顺序the unique non-ambiguous order defined by the formal grammar

Syntax

Formal syntax: [ <length> | <percentage> ] && [ border-box | content-box ]? | available | min-content | max-content | fit-content | auto
height: auto     /* auto keyword */

height: 120px    /* <length> values */
height: 10em

height: 75%      /* <percentage> values */

height: inherit

Values

<length>
可用单位查看 <length>
<percentage>
<percentage> 相对于元素的块容器高度。如果块容器的高度没有显式指定,计算值为 auto。 用在root 元素 (e.g. <html>) 上是相对于初始块容器(即显示器的尺寸)。
auto
由浏览器计算确定。

Example

HTML

<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>

CSS

div {
  width: 250px;
  margin-bottom: 5px;
  border: 3px solid #999999;
}

#red {
  height: 50px;
}

#green {
  height: 25px;
}

#parent {
  height: 100px;
}

#child {
  height: 50%;
  width: 75%;
}

Specifications

Specification Status Comment
CSS Basic Box Model
height
Working Draft Added the max-content, min-content, available, fit-content, border-box, content-box keywords.
CSS Transitions
height
Working Draft Lists height as animatable.
CSS Level 2 (Revision 1)
height
Recommendation Adds support for the <length> values and precises on which element it applies to.
CSS Level 1
height
Recommendation Initial specification.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) 4.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

See also

文档标签和贡献者

 此页面的贡献者: QAQMiao, Sebastianz, SphinxKnight, teoli, yan
 最后编辑者: QAQMiao,