Help us understand the problem. What is going on with this article?

要素を横も縦も中央寄せする方法

More than 5 years have passed since last update.

要素を縦も横も中央寄せする方法。
tableでも同じように出来るけど、他の要素でやりたい場合。
この方法は、外側のタグのサイズに依存する場合に便利。

all_center_baseで縦横確保して、all_center_innerで位置調整をしている。
もし、サイズが決まっているのであれば、all_center_innerを付けている要素にサイズを設定すればall_center_baseタグは要らない。

この方法の他にもやり方はあるので、場合によって使い分ける。

.all_center_base {
    display: table;
    width: 100%;
    height: 100%;
}
.all_center_inner {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}
<div class="all_center_base">
    <div class="all_center_inner">
        中央寄せしたい要素
    </div>
</div>
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした