flex-grow

flex-growCSS のプロパティで、フレックスアイテムの主軸方向の寸法のフレックス伸長係数を設定します。

試してみましょう

構文

/* <number> 値 */
flex-grow: 3;
flex-grow: 0.6;

/* グローバル値 */
flex-grow: inherit;
flex-grow: initial;
flex-grow: revert;
flex-grow: revert-layer;
flex-grow: unset;

flex-grow プロパティは単一の <number> として指定します。

<number>

<number> をご覧ください。負の値は無効です。既定値は 0 です。

解説

このプロパティは、フレックスコンテナー内の残りの空間のうち、どれだけがそのアイテムに割り当てられるか (フレックス伸長係数) を設定します。

主軸方向の寸法は、アイテムの幅または高さのどちらかで、 flex-direction の値に依存して決まります。

残りの空間とは、フレックスコンテナーの寸法からすべてのフレックスアイテムの寸法を引いたものです。すべての兄弟アイテムが同じフレックス伸長係数であった場合、すべてのアイテムには残りの空間が等しく割り当てられ、そうでなければ定義されたそれぞれフレックス伸長係数の比率に従って分配されます。

使用するにあたって、 flex-grow は他のフレックスプロパティである flex-shrinkflex-basis とともに使用され、通常はすべての値が設定されることを保証するために一括指定の flex を使用して定義します。

公式定義

初期値0
適用対象フロー内の擬似要素を含むフレックスアイテム
継承なし
計算値指定通り
アニメーションの種類数値

形式文法

flex-grow = 
<number [0,∞]>

フレックスアイテムの伸長係数の設定

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);
}

結果

仕様書

Specification
CSS Flexible Box Layout Module Level 1
# flex-grow-property

ブラウザーの互換性

BCD tables only load in the browser

関連情報