Flexbox-justifying-contents
Flexbox-内容の正当化
多くの場合、以下に示すようにフレックスアイテムを配置した後、コンテナ内に余分なスペースが残っています。
プロパティ justify-content を使用すると、余分なスペースを意図したとおりに分配することにより、メイン軸に沿ってコンテンツを整列できます。 また、flexitemsが行をオーバーフローする場合に備えて、flexitemsの配置を調整できます。
使用法-
justify-content: flex-start | flex-end | center | space-between | space-around| space-evenly;
このプロパティは、次の値を受け入れます-
- flex-start -flex-itemsはコンテナの先頭に配置されます。
- flex-end -flex-itemsはコンテナの最後に配置されます。
- center -flex-itemsはコンテナの中央に配置され、余剰スペースはflex-itemsの最初と最後に均等に分配されます。
- space-between -追加のスペースはflex-item間に均等に分配されます。
- space-around -余分なスペースは、コンテナとその内容物の間のスペースがflex-item間のスペースの半分になるようにflexアイテム間に均等に分配されます。
ここで、justify-contentプロパティの使用方法と例を示します。
フレックススタート
この値をプロパティ justify-content に渡すと、フレックスアイテムはコンテナの先頭に配置されます。
次の例は、値 flex-start を justify-content プロパティに渡した結果を示しています。
<!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:flex;
border:3px solid black;
justify-content:flex-start;
}
</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>
それは次の結果を生成します-
フレックスエンド
この値をプロパティ justify-content に渡すと、フレックスアイテムはコンテナの最後に配置されます。
次の例は、値 flex-end を justify-content プロパティに渡した結果を示しています。
<!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:flex;
border:3px solid black;
justify-content:flex-end;
}
</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>
それは次の結果を生成します-
センター
この値をプロパティ justify-content に渡すと、flex-itemsがコンテナの中心に配置され、余分なスペースがflex-itemsの開始時と終了時に均等に分配されます。
次の例は、値 center を justify-content プロパティに渡した結果を示しています。
<!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:flex;
border:3px solid black;
justify-content:center;
}
</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>
それは次の結果を生成します-
スペース間
この値をプロパティ justify-content に渡すと、2つのflexアイテム間のスペースが同じになり、flexアイテムの開始と終了がの端に触れるように、余分なスペースがflexアイテム間に均等に分配されます。コンテナ。
次の例は、値 space-between を justify-content プロパティに渡した結果を示しています。
<!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:flex;
border:3px solid black;
justify-content:space-between;
}
</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>
それは次の結果を生成します-
スペースアラウンド
この値をプロパティ justify-content に渡すと、任意の2つのflex-item間のスペースが同じになるように、余分なスペースがflex-item間に均等に分配されます。 ただし、コンテナの端とその内容(フレックス項目の開始と終了)の間のスペースは、フレックス項目間のスペースの半分です。
次の例は、値 space-around を justify-content プロパティに渡した結果を示しています。
<!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:flex;
border:3px solid black;
justify-content:space-around;
}
</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>
それは次の結果を生成します-
スペース均等
この値をプロパティ justify-content に渡すと、2つのflexアイテム間のスペースが同じになるように、余分なスペースがflexアイテム間に均等に分配されます(端までのスペースを含む)。
次の例は、値 space-evenly を justify-content プロパティに渡した結果を示しています。
<!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:flex;
border:3px solid black;
justify-content:space-evenly;
}
</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>
それは次の結果を生成します-