0

I have the following container setup where

  • the entire page is split in half, left and right
  • the left container is split into two separate containers, an upper and a lower one

The lower one will have dynamic content in the future but I used a spacer to keep the layout and added a content container to the lower one.

The problem is that if I apply a margin-top to the content container inside the lower container, the margin gets applied to the lower spacer creating a gap between the upper and lower. I can't wrap my head around this and when I rebuild this in a blank page with just the up and down split in a container it worked fine.

* {
  margin: 0px;
  padding: 0px;
}

#left {
  width: 50%;
  height: 100%;
  float: left;
  background-color: #333;
}

#upper-spacer {
  width: 100%;
  height: 20%;
  background-color: #f00;
}

#lower-spacer {
  width: 100%;
  height: 80%;
  background-color: #28a87a;
}

#lower-content {
  width: 90%;
  margin: auto;
  margin-top: 20px;
  height: 80%;
  background-color: #1d77c6;
}

#right {
  width: 50%;
  height: 100%;
  float: right;
  background-color: #3c3c3c;
}
<div>
  <div id="left">
    <div id="upper-spacer"></div>
    <div id="lower-spacer">
      <div id="lower-content"></div>
    </div>
  </div>
  <div id="right"></div>
</div>

I am not only looking for and easy fix but more for a explanation.

j08691
  • 204,283
  • 31
  • 260
  • 272
  • You are seeing "margin collapse". Google for that or search on SO for a ton of answers about it. – Rob Aug 09 '17 at 20:47
  • Possible duplicate of [How to disable margin-collapsing?](https://stackoverflow.com/questions/19718634/how-to-disable-margin-collapsing) – Rob Aug 09 '17 at 20:49
  • Whoever made the run code snippet thing it doesn't even resemble a tiny amount of what I see when I run it locally just a side note thanks anyway. – seeyouinthefuture Aug 10 '17 at 17:01

0 Answers0