LoginSignup
0
0

More than 3 years have passed since last update.

CSSで要素を中央に配置する

Posted at

プログラミングの勉強日記

2020年6月30日 Progate Lv.148
ポートフォリオ作成中
縦横方向に中央揃えにする。

目標物

 下の写真のように要素を真ん中に配置したい。横方向で真ん中にするためにはtext-align: center;の方法があるが、今回は親要素に対してど真ん中に配置する。

0630.PNG

コード

 親要素にdisplay:flexjustify-content: centeralign-items: centerを追加する。

align-itemsプロパティ:フレックスアイテムの交差軸方向のアイテムの配置を制御する。
justify-contentプロパティ:フレックスアイテムの主軸の方向の揃え位置を指定する。

HTMLファイル
<div class="parent">
  <div class="children">
    <!-- コード -->
  </div>
</div>
CSSファイル
.parent {
  display: flex;
  justify-content: center;
  align-items: center;
}
0
0
0

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
0
0