0
0

More than 3 years have passed since last update.

【cssメモ】cssで中央揃え

Last updated at Posted at 2021-08-14

◇本日のメモ

cssにて、中央にする方法

①文字を中央揃え

css
{text-align: center;}

②要素を中央揃え

css
{margin:0 auto;}

③display: flexにて中央揃え
こちらは記述した【子要素】が横並びになる。
なので、横並びにしたいものからみて、その親要素に記述
例えば親要素のdiv内にで3つの子要素があれば、親要素にdisplay: flexを記述して、その3つを横並ぶにする

css
{
 display: flex;
}

◇おまけ
display: flexのオプション。下記記述で縦並びに上下左右中央になる

css
{
  display: flex;
  flex-direction: column; /* 横要素にしたのを、縦並びに*/
  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