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.

[CSS]<header>と<main>の背景や文字が重なる?

Posted at

はじめに

本記事では、私が昨日
headerとmainの背景や文字が重なることを解決した方法を記述します。

結論

いきなり結論ですが、
position absoluteが邪魔をしています。

これを記述していることで、本来下に来るはずので記述したものが、
出て来なくなります。

超簡単ですが、

<div class="contents">
   <div class="top-content"> 
   </div>
   <div class="bottom-content">
   </div>
</div>
.top-content{
  height: 250px;
  width: 500px;
  background-color: lightcoral;
}

.bottom-content{
  height: 250px;
  width: 500px;
  background-color: lightblue;
}

<div class="contents">
   <div class="top-content"> 
   </div>
   <div class="bottom-content">
   </div>
</div>
.top-content{
  height: 250px;
  width: 500px;
  background-color: lightcoral;
  position: absolute;
}

.bottom-content{
  height: 250px;
  width: 500px;
  background-color: lightblue;
}

というものがあったとします。

実際の図

position absoluteの画像1.png

position absoluteの画像2.png

青色が消えました。

position absoluteを使用すると、
「位置が浮いてしまう」というみたいです。

終わりに

結論はかなり簡単な話でしたが、
何時間も悩んでいました。

悩んでいる途中で検証を使ったらかなり便利なことに気がつき、
検証で原因を突き止めました。

CSSで実験をしたいとき、検証を使うと良いかもしれませんね!

以下参考サイトです。
position:absoluteを使うと次のブロックが重なってしまう
CSSのposition:absoluteとrelativeの使い方を理解する!要素を重ねる方法

明日も頑張ろう!!

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?