0
0

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.

CSSでblock要素を上下左右中央寄せにできなかった原因と解決

Posted at

問題

CSSでblock要素を上下左右中央寄せしたくて

position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 任意の値
height: 任意の値

こんな感じのCSSを入れたけど、上手くいかなかった。

原因&解決

別CSSファイルで

* {
  margin:0;
  padding:0;
}

を入れていて、この margin:0; が原因だった。

position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto; /* <-- 追加 */
width: 任意の値
height: 任意の値

これで解決。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?