【CSS3】【Flexbox】justify-contentの使い方
要素の位置を左、右、中央のように水平方向に指定したい場合はjustify-contentを使用します。
justify-contentはフレックスボックスだけでなくグリッドレイアウトにも使用できます。justify-content:flex-startjustify-content:flex-startを指定すると左揃えにできます。
display:flex;justify-content:flex-start;
  See the Pen 
  justify-content1 by shiakisudev (@shiakisu)
  on CodePen.
HTML
<div id="container1">
  <div>A</div>
  <div>B</div>
  <div>C</div>
  <div>D</div>
</div>
CSS
#container1{
  display:flex;
  justify-content:flex-start;
  height:50px;
  width:180px;
  border: 1px black solid;
}
#container1 > div{
  height:30px;
  width:30px;
  box-sizing:border-box;
  border: 1px black solid;
  background-color:lime;
}
justify-content:flex-endjustify-content:flex-endを指定すると右揃えにできます。
display:flex;justify-content:flex-end;
  See the Pen 
   by shiakisudev (@shiakisu)
  on CodePen.
HTML
<div id="container2">
  <div>A</div>
  <div>B</div>
  <div>C</div>
  <div>D</div>
</div>
CSS
#container2{
  display:flex;
  justify-content:flex-end;
  height:50px;
  width:180px;
  border: 1px black solid;
}
#container2 > div{
  height:30px;
  width:30px;
  box-sizing:border-box;
  border: 1px black solid;
  background-color:lime;
}
justify-content:centerjustify-content:centerを指定すると中央揃えにできます。
display:flex;justify-content:center;
  See the Pen 
  justify-content3 by shiakisudev (@shiakisu)
  on CodePen.
HTML
<div id="container3">
  <div>A</div>
  <div>B</div>
  <div>C</div>
  <div>D</div>
</div>
CSS
#container3{
  display:flex;
  justify-content:center;
  height:50px;
  width:180px;
  border: 1px black solid;
}
#container3 > div{
  height:30px;
  width:30px;
  box-sizing:border-box;
  border: 1px black solid;
  background-color:lime;
}
justify-content:space-betweenjustify-content:space-betweenを指定すると両端揃えにできます。
間にある要素は、間隔を開けて均等揃えになります。
display:flex;justify-content:space-between;
  See the Pen 
  justify-content4 by shiakisudev (@shiakisu)
  on CodePen.
HTML
<div id="container4">
  <div>A</div>
  <div>B</div>
  <div>C</div>
  <div>D</div>
</div>
CSS
#container4{
  display:flex;
  justify-content:space-between;
  height:50px;
  width:180px;
  border: 1px black solid;
}
#container4 > div{
  height:30px;
  width:30px;
  box-sizing:border-box;
  border: 1px black solid;
  background-color:lime;
}
justify-content:space-aroundjustify-content:space-aroundを指定すると最初と最後の要素も含めて均等揃えになります。
このとき、両端の間隔の大きさは、残りの要素の間隔の大きさの半分になります。
display:flex;justify-content:space-around;
  See the Pen 
  ustify-content5 by shiakisudev (@shiakisu)
  on CodePen.
HTML
<div id="container5">
  <div>A</div>
  <div>B</div>
  <div>C</div>
  <div>D</div>
</div>
CSS
#container5{
  display:flex;
  justify-content:space-around;
  height:50px;
  width:180px;
  border: 1px black solid;
}
#container5 > div{
  height:30px;
  width:30px;
  box-sizing:border-box;
  border: 1px black solid;
  background-color:lime;
}
justify-content:space-evenlyjustify-content:space-evenlyを指定すると間隔の大きさも均等に、均等揃えになります。
  See the Pen 
  justify-content6 by shiakisudev (@shiakisu)
  on CodePen.
HTML
<div id="container6">
  <div>A</div>
  <div>B</div>
  <div>C</div>
  <div>D</div>
</div>
CSS
#container6{
  display:flex;
  justify-content:space-evenly;
  height:50px;
  width:180px;
  border: 1px black solid;
}
#container6 > div{
  height:30px;
  width:30px;
  box-sizing:border-box;
  border: 1px black solid;
  background-color:lime;
}
  See the Pen 
  justify-content-all by shiakisudev (@shiakisu)
  on CodePen.
以上で記事の解説はお終い!
HTML、CSS、JavaScriptをもっと勉強したい方にはUdemyがオススメ!同僚に差をつけよう!