2

HTML and CSS below. Div id "black" seems to be pushing a space between itself and the "brown" div above it. When I remove the "black" div, the excess space disappears. I have all margins and padding at zero. Can't sort out what's causing this. ANy suggestions are appreciated.

html {
  padding: 0;
  margin: 0;
}
body {
  font-size: 62.5%;
  margin: 0;
  padding: 0;
  text-align: center;
  font-family: raleway;
  font-style: normal;
  font-weight: 400;
  color: #000000;
}
#greyWrapper {
  background-color: #303030;
  margin: 0;
  padding: 0;
  width: 100%;
  color: #FFFFFF;
  height: auto;
}
#Brown {
  margin: 0px;
  padding: 0px;
  width: 100%;
  height: auto;
  background-color: #644015;
}
#Brown ul {
  text-decoration: none;
  list-style-type: none;
  text-transform: uppercase;
  font-size: 0.7em;
  margin: 0;
  padding: 0;
}
#Brown ul li {
  display: inline-block;
  padding-top: 5px;
  padding-right: 10px;
  padding-bottom: 5px;
  padding-left: 10px;
}
#black {
  background-repeat: no-repeat;
  margin: 0px;
  padding: 0px;
  width: 100%;
  background-color: #000000;
  height: auto;
}
<div id="greyWrapper">
  <div id="Brown">
    <ul>
      <li>Home</li>
      <li>About</li>
      <li>Portfolios</li>
      <li>Team</li>
      <li>Blog</li>
      <li>Contact</li>
    </ul>
  </div>
  <div id="black">
    <p>Grab Your Copy Of</p>
    <p>The Premium Quality PSD Template</p>
    <p>For free Download</p>
  </div>
</div>
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Murf17
  • 23
  • 5

2 Answers2

3

Your ps have a margin and this margin extends beyond the limits of the #black div and "push against" the #brown div. There's a good explanation in Why does this CSS margin-top style not work?

You can either:

  • Put a border around #black. The border will force the div to expand so that it contains all of the margins of the children.
#black {
    border: 1px solid black;
}

or

  • Remove the top margin of the topmost paragraph
#black > p:first-child {
    margin-top: 0px;
}
Community
  • 1
  • 1
abl
  • 5,970
  • 4
  • 25
  • 44
2

It's the automatic margin-before on the <p> tag that is applied by most browsers. Set:

#black p {
    margin: 0
}

and you'll see it go away.

Joshua Whitley
  • 1,196
  • 7
  • 21