Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

White space appears when using margin-top

Tags:

html

css

I am attempting to use margin-top push a container down relative to its parent container. However, when trying to do so, a white gap is appearing between the parent div and the preceeding div (see screenshots). I am wondering if anyone has a solutionenter image description here for this.

enter image description here

enter image description here

like image 558
thebighoncho Avatar asked Sep 18 '25 19:09

thebighoncho


1 Answers

Use padding, not margin if the issue is that the background isn't getting filled in. This applies to the parent div, not the child:

http://jsfiddle.net/tmd4thpa/

.container {
  background: purple;
  padding:20px;
}
.div {
  height:500px;
  background: red;
}
<div class="container">
  <div class="div"></div>
</div>
like image 81
austinthedeveloper Avatar answered Sep 21 '25 11:09

austinthedeveloper