flex-grow CSS property sets the flex grow factor of a flex item main size .

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

句法

/* <number> values */
flex-grow: 3;
flex-grow: 0.6;
/* Global values */
flex-grow: inherit;
flex-grow: initial;
flex-grow: unset;
					

flex-grow property is specified as a single <number> .

<number>
<number> . Negative values are invalid. Defaults to 0.

描述

This property specifies how much of the remaining space in the flex container should be assigned to the item (the flex grow factor).

main size is either width or height of the item which is dependent on the flex-direction 值。

The remaining space is the size of the flex container minus the size of all flex items' sizes together. If all sibling items have the same flex grow factor, then all items will receive the same share of remaining space, otherwise it is distributed according to the ratio defined by the different flex grow factors.

flex-grow is used alongside the other flex properties flex-shrink and flex-basis , and normally defined using the flex shorthand to ensure all values are set.

形式定义

初始值 0
适用于 flex items, including in-flow pseudo-elements
继承 no
计算值 如指定
动画类型 a number

形式句法

<number>
					

范例

Setting flex item grow factor

HTML

<h4>This is a Flex-Grow</h4>
<h5>A,B,C and F are flex-grow:1 . D and E are flex-grow:2 .</h5>
<div id="content">
  <div class="box" style="background-color:red;">A</div>
  <div class="box" style="background-color:lightblue;">B</div>
  <div class="box" style="background-color:yellow;">C</div>
  <div class="box1" style="background-color:brown;">D</div>
  <div class="box1" style="background-color:lightgreen;">E</div>
  <div class="box" style="background-color:brown;">F</div>
</div>
					

CSS

#content {
  display: flex;
  justify-content: space-around;
  flex-flow: row wrap;
  align-items: stretch;
}
.box {
  flex-grow: 1;
  border: 3px solid rgba(0,0,0,.2);
}
.box1 {
  flex-grow: 2;
  border: 3px solid rgba(0,0,0,.2);
}
					

结果

规范

规范 状态 注释
CSS Flexible Box Layout Module
The definition of 'flex-grow' in that specification.
候选推荐 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
flex-grow Chrome 完整支持 29 Edge 完整支持 12 Firefox 完整支持 20 注意事项
完整支持 20 注意事项
注意事项 Since Firefox 28, multi-line flexbox is supported.
不支持 18 — 20 Disabled
Disabled ). To change preferences in Firefox, visit
IE 完整支持 11
完整支持 11
完整支持 10 Alternate Name
Alternate Name Uses the non-standard name: -ms-flex-positive
Opera 完整支持 12.1 Safari 完整支持 9 WebView Android 完整支持 4.4 Chrome Android 完整支持 29 Firefox Android 完整支持 20 注意事项
完整支持 20 注意事项
注意事项 Since Firefox 28, multi-line flexbox is supported.
不支持 18 — 20 Disabled
Disabled ). To change preferences in Firefox, visit
Opera Android 完整支持 12.1 Safari iOS 完整支持 9 Samsung Internet Android 完整支持 2.0
<0 animate 非标 Chrome 完整支持 49 Edge 完整支持 79 Firefox 完整支持 32 注意事项
完整支持 32 注意事项
注意事项 Before Firefox 32, Firefox wasn't able to animate values starting or stopping at 0 .
IE 不支持 No Opera 完整支持 36 Safari 不支持 No WebView Android 完整支持 49 Chrome Android 完整支持 49 Firefox Android 完整支持 32 注意事项
完整支持 32 注意事项
注意事项 Before Firefox 32, Firefox wasn't able to animate values starting or stopping at 0 .
Opera Android 完整支持 36 Safari iOS 不支持 No Samsung Internet Android 完整支持 5.0

图例

完整支持

完整支持

不支持

不支持

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

见实现注意事项。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

使用非标名称。

使用非标名称。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

另请参阅

元数据

  • 最后修改: