6
6

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.

widthが可変の要素を中央に配置する

Posted at

テキスト等、可変長の要素を中央に配置する場合、
親要素にtext-align: center;、子要素にdisplay: inline-block;と指定する事で中央に配置出来ますが、
複数行のテキストの場合は上記では実現出来ません。

以下のようにdisplay: table;を使う事によって実現できます。

.block {
  display: table;
  margin: 0 auto;
}

親要素へのスタイル指定も不要なので便利です。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?