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

CSSのpaddingが入らない問題の解決方法

Last updated at Posted at 2025-04-20

問題

paddingが右にも入るはずが入らない。

footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  background: white;
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

image.png

解決方法

width: 100%に加えて、左右のpadding: 10px分がはみ出てしまっていた。
box-sizingプロパティを追加することで解決できた。

footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  background: white;
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box; /* これを追加 */
}

image.png

終わりに

どこが悪いのかすぐに分からず、難しかったです。
box-sizing: border-box;を追加することで、paddingが正しく適用されるようになりました。

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