0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

text-align:centerとmargin 0 autoの違い

Posted at
Page 1 of 2

インライン要素とアウトライン要素

cssの基礎知識です。理解してから進みましょう。
知っている方は下に進みましょう。

ブロック要素
  • div
  • p
  • ul
  • header
  • footer
    等々があります。まだまだ数知れずありますが徐々に慣れていきます。

https://web-firstlog.com/wp-content/uploads/2017/12/blockinline1.svg
リンクを見てもらえばわかると思いますが、要素が横いっぱいに広がり次の要素が下に配置されます。

インライン要素

  • span
  • a
  • image
  • br
    などなど。こちらもブロック要素と同じでたくさんあります。

https://web-firstlog.com/wp-content/uploads/2017/12/blockinline3.svg
インライン要素は縦に並ばず横に並んでいきます。

htmlは左上に重心がある積み木のようなものなのでブロックと要素だと縦に並んでいきます。

ここまで理解できたら本題です。
と言っても簡単です。

ブロック要素はmargin 0 autoを使い、インライン要素はtext-align:centerを使います。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?