Flexbox-flex-direction
フレックスボックス-フレックス方向
*flex-direction* プロパティは、フレックスコンテナ(flex-items)の要素を配置する必要がある方向を指定するために使用されます。
使用法-
flex-direction: row | row-reverse | column | column-reverse
このプロパティは、4つの値を受け入れます-
- row -コンテナの要素を左から右に水平に配置します。
- row-reverse -コンテナの要素を右から左に水平に配置します。
- column -コンテナの要素を左から右に垂直に配置します。
- column-reverse -コンテナの要素を右から左に垂直に配置します。
ここで、 direction プロパティの使用を示すためにいくつかの例を取り上げます。
row
この値を direction プロパティに渡すと、以下に示すように、コンテナの要素が左から右に水平に配置されます。
次の例は、値 row を_flex-direction_プロパティに渡した結果を示しています。 ここでは、_flex-direction_値が row の異なる色の6つのボックスを作成しています。
<!doctype html>
<html lang = "en">
<style>
.box1{background:green;}
.box2{background:blue;}
.box3{background:red;}
.box4{background:magenta;}
.box5{background:yellow;}
.box6{background:pink;}
.box{
font-size:35px;
padding:15px;
}
.container{
display:inline-flex;
border:3px solid black;
flex-direction:row;
}
</style>
<body>
<div class = "container">
<div class = "box box1">One</div>
<div class = "box box2">two</div>
<div class = "box box3">three</div>
<div class = "box box4">four</div>
<div class = "box box5">five</div>
<div class = "box box6">six</div>
</div>
</body>
</html>
それは次の結果を生成します-
行反転
この値を direction プロパティに渡すと、以下に示すように、コンテナの要素が右から左に水平に配置されます。
次の例は、値 row-reverse を_flex-direction_プロパティに渡した結果を示しています。 ここでは、_flex-direction_値 row-reverse で異なる色の6つのボックスを作成しています。
<!doctype html>
<html lang = "en">
<style>
.box1{background:green;}
.box2{background:blue;}
.box3{background:red;}
.box4{background:magenta;}
.box5{background:yellow;}
.box6{background:pink;}
.box{
font-size:35px;
padding:15px;
}
.container{
display:inline-flex;
border:3px solid black;
flex-direction:row-reverse;
}
</style>
<body>
<div class = "container">
<div class = "box box1">One</div>
<div class = "box box2">two</div>
<div class = "box box3">three</div>
<div class = "box box4">four</div>
<div class = "box box5">five</div>
<div class = "box box6">six</div>
</div>
</body>
</html>
それは次の結果を生成します-
カラム
この値を direction プロパティに渡すと、下に示すように、コンテナの要素が上から下に垂直に配置されます。
次の例は、値 column を_flex-direction_プロパティに渡した結果を示しています。 ここでは、_flex-direction_値 column で異なる色の6つのボックスを作成しています。
<!doctype html>
<html lang = "en">
<style>
.box1{background:green;}
.box2{background:blue;}
.box3{background:red;}
.box4{background:magenta;}
.box5{background:yellow;}
.box6{background:pink;}
.box{
font-size:35px;
padding:15px;
}
.container{
display:inline-flex;
border:3px solid black;
flex-direction:column;
}
</style>
<body>
<div class = "container">
<div class = "box box1">One</div>
<div class = "box box2">two</div>
<div class = "box box3">three</div>
<div class = "box box4">four</div>
<div class = "box box5">five</div>
<div class = "box box6">six</div>
</div>
</body>
</html>
それは次の結果を生成します-
列反転
この値を direction プロパティに渡すと、下に示すように、コンテナの要素が下から上に垂直に配置されます。
次の例は、値 column-reverse を_flex-direction_プロパティに渡した結果を示しています。 ここでは、_flex-direction_値 column-reverse で異なる色の6つのボックスを作成しています。
<!doctype html>
<html lang = "en">
<style>
.box1{background:green;}
.box2{background:blue;}
.box3{background:red;}
.box4{background:magenta;}
.box5{background:yellow;}
.box6{background:pink;}
.box{
font-size:35px;
padding:15px;
}
.container{
display:inline-flex;
border:3px solid black;
flex-direction:column-reverse;
}
</style>
<body>
<div class = "container">
<div class = "box box1">One</div>
<div class = "box box2">two</div>
<div class = "box box3">three</div>
<div class = "box box4">four</div>
<div class = "box box5">five</div>
<div class = "box box6">six</div>
</div>
</body>
</html>
それは次の結果を生成します-