Flexbox-align-content

提供:Dev Guides
移動先:案内検索

フレックスボックス-コンテンツの整列

flex-containerに複数の行がある場合(flex-wrap:wrapの場合)、align-contentプロパティはコンテナ内の各行の配置を定義します。

使用法-

align-content: flex-start | flex-end | center | space-between | space-around | stretch;

このプロパティは、次の値を受け入れます-

  • stretch -コンテンツの行は残りのスペースを埋めるために伸びます。
  • flex-start -コンテンツ内のすべての行はコンテナの開始時にパックされます。
  • flex-end -コンテンツ内のすべての行はコンテナの最後に詰め込まれます。
  • center -コンテンツ内のすべての行はコンテナの中央に詰められます。
  • space-between -余分なスペースは行間に均等に配分されます。
  • space-around -余分なスペースは、各行(最初と最後の行を含む)の周りに等しいスペースで均等に行間に分配されます

センター

この値をプロパティ align-content に渡すと、すべての行がコンテナの中央に詰められます。

Flex Align Content-Center

次の例は、値 centeralign-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:25px;
         padding:15px;
         width:43%;
      }
      .container{
         display:flex;
         height:100vh;
         flex-wrap:wrap;
         align-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>

それは次の結果を生成します-

フレックススタート

この値をプロパティ align-content に渡すと、すべての行がコンテナの開始時にパックされます。

Flex Align Content-Start

次の例は、値 flex-startalign-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:25px;
         padding:15px;
         width:40%;
      }
      .container{
         display:flex;
         height:100vh;
         flex-wrap:wrap;
         align-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>

それは次の結果を生成します-

フレックスエンド

この値をプロパティ align-content に渡すと、すべての行がコンテナの最後に詰められます。

Flex Align Content-End

次の例は、値 flex-endalign-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:25px;
         padding:15px;
         width:40%;
      }
      .container{
         display:flex;
         height:100vh;
         flex-wrap:wrap;
         align-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>

それは次の結果を生成します-

ストレッチ

この値をプロパティ align-content に渡すと、行が伸びて残りのスペースがいっぱいになります。

Flex Align Content-Stretch

次の例は、 align-content プロパティに値 stretch を渡した結果を示しています。

<!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:25px;
         padding:15px;
         width:40;
      }
      .container{
         display:flex;
         height:100vh;
         flex-wrap:wrap;
         align-content:stretch;
      }
   </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>

それは次の結果を生成します-

スペースアラウンド

この値をプロパティ align-content に渡すと、余分なスペースが行間に均等に配分され、各行(最初と最後の行を含む)の周りに等しいスペースが配置されます。

Flex Align Content-Space Around

次の例は、値 space-aroundalign-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:25px;
         padding:15px;
         width:40%;
      }
      .container{
         display:flex;
         height:100vh;
         flex-wrap:wrap;
         align-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>

それは次の結果を生成します-

スペース間

この値をプロパティ align-content に渡すと、余分なスペースが行間に均等に配分されます。最初の行はコンテナの一番上にあり、最後の行はコンテナの一番下にあります。

Flex Align Content-Space Between

次の例は、値 space-betweenalign-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:25px;
         padding:15px;
         width:40%;
      }
      .container{
         display:flex;
         height:100vh;
         flex-wrap:wrap;
         align-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>

それは次の結果を生成します-