--- title: flex-direction slug: Web/CSS/flex-direction tags: - CSS - CSS Flexible Boxes - CSS Property - Reference - 'recipe:css-property' translation_of: Web/CSS/flex-direction ---
flex-direction は CSS のプロパティで、主軸の方向や向き (通常または逆方向) を定義することにより、フレックスコンテナー内でフレックスアイテムを配置する方法を設定します。
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
なお、 row および row-reverse の値は、フレックスコンテナーの書字方向に影響されます。 {{HTMLAttrxRef("dir")}} 属性が ltr である場合は、 row は左から右へ向かう水平軸を表し、また row-reverse は右から左へ向かう水平軸を表します。一方、 dir 属性が rtl である場合は、 row は右から左へ向かう水平軸を表し、また row-reverse は左から右へ向かう水平軸を表します。
/* 行のテキストの方向に配置 */ flex-direction: row; /* <row> と同様だが、逆向き */ flex-direction: row-reverse; /* 積み重なるように配置する */ flex-direction: column; /* <column> と同様だが、逆向き */ flex-direction: column-reverse; /* グローバル値 */ flex-direction: inherit; flex-direction: initial; flex-direction: unset;
以下の値を指定できます。
rowrow-reverserow と同様ですが、main-start および main-end の位置が入れ替わります。columncolumn-reversecolumn と同様ですが、 main-start および main-end の位置が入れ替わります。flex-direction プロパティを row-reverse または column-reverse の値で使うと、視覚上の表示と DOM の順序が一致しなくなります。これは、スクリーンリーダーなどの支援技術を使っている視覚障害者に不利な影響を及ぼします。視覚的な (CSS の) 順序が重要である場合は、読み上げソフトの利用者は正しい読み上げ順序でアクセスすることができなくなります。
{{cssinfo}}
<h4>This is a Column-Reverse</h4> <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> <h4>This is a Row-Reverse</h4> <div id="content1"> <div class="box1" style="background-color:red;">A</div> <div class="box1" style="background-color:lightblue;">B</div> <div class="box1" style="background-color:yellow;">C</div> </div>
#content {
width: 200px;
height: 200px;
border: 1px solid #c3c3c3;
display: flex;
flex-direction: column-reverse;
}
.box {
width: 50px;
height: 50px;
}
#content1 {
width: 200px;
height: 200px;
border: 1px solid #c3c3c3;
display: flex;
flex-direction: row-reverse;
}
.box1 {
width: 50px;
height: 50px;
}
{{EmbedLiveSample('Reversing_flex_container_columns_and_rows', '', '550')}}
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName('CSS3 Flexbox', '#flex-direction', 'flex-direction')}} | {{Spec2('CSS3 Flexbox')}} | 初回定義 |
{{Compat("css.properties.flex-direction")}}