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 3 years have passed since last update.

【HTML/CSS】右に謎の余白ができる原因を解明したら、Bootstrap4が悪さしてました。。。

Last updated at Posted at 2020-07-18

はじめに

webページを作成しているとまれに起こる事件!
スクリーンショット 2020-07-18 19.48.05.jpg

そう!ページ全体で右に謎の余白ができる!!

試した事

こちらの回答にある通り、overflow:hidden;を試すと確かに右の謎の余白は無くなった!
が、では原因は何??

スクリーンショット 2020-07-18 19.48.47.jpg

同じミスをしていた人のために、この記事を残すとする!:slight_smile:

原因は2つ!

containerのpaddingを0に上書きしていたから

画面の左右の余白を無くしたいけど、グリッドシステムは使いたい!
そう思って**.containerの左右のpaddingを0にするために上書きした事が原因でした。。。**

.container {
  width: 100%;
  padding-right: 0;
  padding-left: 0;
  margin-right: 0;
  margin-left: 0;
}

rowのネガティブマージンのせいで、containerの幅を超えてしまってた。。

スクリーンショット 2020-07-18 20.55.48.jpg

Bootstrap4のrowでは以下のようなcssが効いている。

.row {
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    margin-right: -15px;
    margin-left: -15px;
}

ここにある左右のネガティブマージンのせいで、rowの幅がcontainerの幅を超えてしまっていたようだ。。

スクリーンショット 2020-07-18 21.03.22.jpg スクリーンショット 2020-07-18 21.03.30.jpg
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?