flex-wrap
CSS の flex-wrap
プロパティは、フレックスアイテムを単一行に押し込むか、あるいは複数行に折り返してもよいかを指定します。折り返しを許可する場合は、行を積み重ねる方向の制御も可能です。
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.
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
他のプロパティや詳細情報については CSS フレックスボックスの利用をご覧ください。
構文
flex-wrap: nowrap; /* 既定値 */
flex-wrap: wrap;
flex-wrap: wrap-reverse;
/* グローバル値 */
flex-wrap: inherit;
flex-wrap: initial;
flex-wrap: unset;
flex-wrap
プロパティは次の値のリストから選択した単一のキーワードで指定します。
値
以下の値を利用することができます。
nowrap
- フレックスアイテムは単一行に配置され、フレックスコンテナーからあふれることもあります。
cross-start
は、flex-direction
の値に応じてstart
またはbefore
と同一になります。 wrap
- フレックスアイテムは複数行に分割されます。
cross-start
はflex-direction
の値に応じてstart
またはbefore
と同一になり、cross-end
は、指定されたcross-start
の反対側になります。 wrap-reverse
wrap
と同様に動作しますが、cross-start
とcross-end
が入れ替わります。
形式文法
例
HTML
<h4>This is an example for flex-wrap:wrap </h4>
<div class="content">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>
<h4>This is an example for flex-wrap:nowrap </h4>
<div class="content1">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>
<h4>This is an example for flex-wrap:wrap-reverse </h4>
<div class="content2">
<div class="red">1</div>
<div class="green">2</div>
<div class="blue">3</div>
</div>
CSS
/* Common Styles */
.content,
.content1,
.content2 {
color: #fff;
font: 100 24px/100px sans-serif;
height: 150px;
text-align: center;
}
.content div,
.content1 div,
.content2 div {
height: 50%;
width: 50%;
}
.red {
background: orangered;
}
.green {
background: yellowgreen;
}
.blue {
background: steelblue;
}
/* Flexbox Styles */
.content {
display: flex;
flex-wrap: wrap;
}
.content1 {
display: flex;
flex-wrap: nowrap;
}
.content2 {
display: flex;
flex-wrap: wrap-reverse;
}
結果
仕様書
仕様書 | 状態 | 備考 |
---|---|---|
CSS Flexible Box Layout Module flex-wrap の定義 |
勧告候補 |
初期値 | nowrap |
---|---|
適用対象 | フレックスコンテナー |
継承 | なし |
計算値 | 指定通り |
アニメーションの種類 | 離散値 |
ブラウザーの対応
BCD tables only load in the browser
このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 https://github.com/mdn/browser-compat-data をチェックアウトしてプルリクエストを送信してください。
関連情報
- CSS フレックスボックスガイド: フレックスボックスの基本概念
- CSS フレックスボックスガイド: フレックスアイテムの折り返しのマスター