Flexbox-flex-wrap
フレックスボックス-フレックスラップ
一般的に、コンテナのスペースが不足している場合、以下に示すように残りのフレックスアイテムは非表示になります。
*flex-wrap* プロパティは、flex-containerが単一行か複数行かを制御するために使用されます。
使用法-
flex-wrap: nowrap | wrap | wrap-reverse
flex-direction: column | column-reverse
このプロパティは、次の値を受け入れます-
- wrap -スペースが不足している場合、コンテナの要素(flexitems)は上から下に追加のflexラインにラップされます。
- wrap-reverse -スペースが不足している場合、コンテナの要素(flex-items)は下から上に追加のflexラインにラップされます。
次に、 wrap プロパティの使用方法と例を示します。
wrap
値 wrap をプロパティ flex-wrap に渡すと、以下のようにコンテナの要素が左から右に水平に配置されます。
次の例は、値 wrap を_flex-wrap_プロパティに渡した結果を示しています。 ここでは、_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;
width:100px;
}
.container{
display:flex;
border:3px solid black;
flex-direction:row;
flex-wrap:wrap;
}
</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>
それは次の結果を生成します-
折り返し
値 wrap-reverse をプロパティ flex-wrap に渡すと、以下に示すようにコンテナの要素が左から右に水平に配置されます。
次の例は、値 wrap-reverse を_flex-wrap_プロパティに渡した結果を示しています。 ここでは、_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;
width:100px;
}
.container{
display:flex;
border:3px solid black;
flex-direction:row;
flex-wrap:wrap-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>
それは次の結果を生成します-
ラップ(列)
値 wrap をプロパティ flex-wrap に渡し、値 column をプロパティ flex-direction に渡すと、下に示すようにコンテナの要素が左から右に水平に配置されます。
次の例は、値 wrap を flex-wrap プロパティに渡した結果を示しています。 ここでは、_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;
width:100px;
}
.container{
display:flex;
border:3px solid black;
flex-direction:column;
flex-wrap:wrap;
height:100vh;
}
</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>
それは次の結果を生成します-
折り返し(列)
値 wrap-reverse をプロパティ flex-wrap に渡し、値 column をプロパティ flex-direction に渡すと、以下に示すように、コンテナの要素が左から右に水平に配置されます。
次の例は、値 wrap-reverse を_flex-wrap_プロパティに渡した結果を示しています。 ここでは、異なる色と_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;
width:100px;
}
.container{
display:flex;
border:3px solid black;
flex-direction:column;
flex-wrap:wrap-reverse;
height:100vh;
}
</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>
それは次の結果を生成します-