LoginSignup
12
17

More than 5 years have passed since last update.

Flex-box 親要素に指定するプロパティ

Last updated at Posted at 2017-11-30

よく使うFlexboxですが、時々、あれ?思う通りにいかないってことがあったりするので、いまいちどチートシートを参考に勉強。

参照

クリエイターボックスさんのチートシート
https://www.webcreatorbox.com/tech/css-flexbox-cheat-sheet

基本の書き方

・ Flexコンテナー(親要素)
・Flexアイテム(子要素)

.container Flexコンテナー
  .item Flexアイテム1
  .item Flexアイテム2
  .item Flexアイテム3
  .item Flexアイテム4

スクリーンショット 2017-11-30 17.02.45.png

Flexコンテナー(親要素)に指定するプロパティ

display:flex;

要素を横並びにする
インライン要素に使うときは  display:inline-flex;
スクリーンショット 2017-11-30 17.01.14.png

flex-direction

子要素の並ぶ向きを指定する

 flex-direction:row(初期値)
スクリーンショット 2017-11-30 17.04.25.png

flex-direction:row-reverse
スクリーンショット 2017-11-30 17.05.34.png

flex-direction:column
スクリーンショット 2017-11-30 17.06.47.png

flex-direction:column-reverse
スクリーンショット 2017-11-30 17.07.44.png

flex-wrap

こ要素を一行もしくは折り返して複数行に配置するかどうかを指定する
子要素が親要素の幅に収まらなくなった場合、折り返して複数行に配置される

flex-wrap:nowrap(初期値)
スクリーンショット 2017-11-30 17.01.14.png

flex-wrap:wrap
スクリーンショット 2017-11-30 17.09.09.png

flex-wrap:wrap-reverse
スクリーンショット 2017-11-30 17.14.50.png

justify-content

水平方向の揃えを指定する

justify-content:flex-start(初期値)
左揃え
スクリーンショット 2017-11-30 17.01.14.png

justify-content:flex-end
右揃え
スクリーンショット 2017-11-30 17.20.39.png

justify-content:center
中央揃え
スクリーンショット 2017-11-30 17.22.07.png

justify-content:space-between
最初と最後の子要素を両端に配置し、残りの要素は均等に間隔をあけて配置
スクリーンショット 2017-11-30 17.22.47.png

justify-content:space-around
両端の子要素も含め、均等に間隔をあけて配置
スクリーンショット 2017-11-30 17.23.54.png

align-items

垂直方向の揃え

align-items:stretch
親要素の高さ、またはコンテンツの一番多い子要素の高さに合わせて広げて配置
スクリーンショット 2017-11-30 17.38.45.png

align-items:flex-start
親要素の開始位置から配置。上揃え。
スクリーンショット 2017-11-30 17.40.19.png

align-items:flex-end
親要素の終点から配置。下揃え。
スクリーンショット 2017-11-30 17.40.19.png

align-items:center
中央揃え
スクリーンショット 2017-11-30 17.42.02.png

align-items:baseline
ベースラインで揃える
スクリーンショット 2017-11-30 17.42.53.png

align-content

複数行にした時の揃えを指定する
flex-wrap: nowrap; が適応されていると子要素が一行になるので、align-content は無効になる。

align-content:stretch
スクリーンショット 2017-11-30 17.49.36.png

align-content:flex-start
スクリーンショット 2017-11-30 17.51.24.png

align-content:flex-end
スクリーンショット 2017-11-30 17.52.21.png

align-content:center
スクリーンショット 2017-11-30 17.53.19.png

align-content:space-between
スクリーンショット 2017-11-30 17.54.13.png

align-content:space-around
スクリーンショット 2017-11-30 17.55.06.png

12
17
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
17