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

height CSS 属性指定了一个元素的高度。默认情况下,这个属性决定的是内容区( content area)的高度,但是,如果将 box-sizing 设置为  border-box , 这个属性决定的将是边框区域(border area)的高度。
min-heightmax-height 属性会覆盖  height

语法

/* Keyword value */
height: auto;

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

/* <percentage> value */
height: 75%;

/* Global values */
height: inherit;
height: initial;
height: unset;

<length>
将高度定义为一个绝对值。
<percentage>
将高度定义为相对包含块高度的百分比。
border-box 
如果设置该值,则 <length> 或者 <percentage> 会设置为该元素的 border box。
content-box 
如果设置该值,则 <length> 或者 <percentage> 会设置为该元素的 content box。
auto
由浏览器为元素计算并选择一个高度。
fill 
Use the fill-available inline size or fill-available block size, as appropriate to the writing mode.
max-content 
The intrinsic preferred height.
min-content 
The intrinsic minimum height.
available 
包含块高度减去当前元素的边距,边框和填充。
fit-content 
The larger of:
  • the intrinsic minimum height
  • the smaller of the intrinsic preferred height and the available height

Formal syntax

[ <length> | <percentage> ] && [ border-box | content-box ]? | available | min-content | max-content | fit-content | auto

示例

HTML

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

CSS

div {
  width: 250px;
  margin-bottom: 5px;
  border: 2px solid blue;
}

#taller {
  height: 50px;
}

#shorter {
  height: 25px;
}

#parent {
  height: 100px;
}

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

结果

无障碍问题

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. 

规范

Specification Status Comment
CSS Basic Box Model
height
Working Draft Added the max-contentmin-contentavailablefit-contentborder-boxcontent-boxkeywords.
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 definition.
CSS Intrinsic & Extrinsic Sizing Module Level 3
width
Working Draft Adds new sizing keywords for width and 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

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support 7Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 4Opera Android Full support 1Safari iOS Full support 1Samsung Internet Android Full support Yes
fillChrome Full support 46Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 46Chrome Android Full support 46Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android Full support 5.0
fit-contentChrome Full support 46Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 46Chrome Android Full support 46Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android Full support 5.0
max-contentChrome Full support 46Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 46Chrome Android Full support 46Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android Full support 5.0
min-contentChrome Full support 46Edge ? Firefox ? IE ? Opera ? Safari ? WebView Android Full support 46Chrome Android Full support 46Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android Full support 5.0

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

参见

文档标签和贡献者

标签: 
此页面的贡献者: Ende93, yongchenyc, mozhs, NNNaix, QAQMiao, Sebastianz, SphinxKnight, teoli, yan
最后编辑者: Ende93,