ale19 ale19 - 1 month ago 14
CSS Question

Whitespace between divs

I know there are a million questions about div gaps, but I can't seem to get any of the solutions to work for me. My webpage currently looks like this:

enter image description here

There is a noticeable gap between the image banner and the text. I want to shorten that so that it looks more like this:

enter image description here

I am pretty sure this is an issue with the CSS for one of my divs, but I'm not sure what. Here is what the inspector looks like, if that helps:

enter image description here

I have tried making a new class in my bootstrap.min.css that has no top padding for both the col-lg-12 div and the row div, but that didn't change anything. I'm not really sure where to go from here.

Here is my code (and here is the website in action on JSFiddle). (I only copy/pasted the relevant parts of it, since the whole code is very long. I apologize if any of the code is wrong or confusing!)

<div class="intro-header-homepage">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="intro-message">
<h1>Website Homepage</h1>
</div>
</div>
</div>

</div>
</div>

<div class="row">
<div class = "col-lg-6 col-lg-offset-3" text-align="center">
<p class="p-homepage">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</body>


CSS:

.p-homepage {
padding: 0px 0px 30px 0px;
font-weight: normal;
font-size: 18px;
}
.intro-header-homepage {
text-align: center;
color: #f8f8f8;
background: url(http://imgur.com/20qY3EH.jpg) no-repeat;
background-size: 100% 80%;
}

.intro-message {
padding-top: 20%;
padding-bottom: 20%;
}

Answer Source

The padding on .intro-message is pushing the text down. There are a few ways of fixing this, but the simplest would be to give the text (p.homepage) a negative margin-top of about 10% to counter the padding. The only thing this will change is the position of the text.

body,
html {
  width: 100%;
  height: 100%;
}

body,
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: "Lato", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: 700;
}

.p-homepage {
  padding: 0px 0px 30px 0px;
  font-weight: normal;
  font-size: 18px;
  margin-top: -10%;
}

.navbar-sticky-top {
  /* add navbar */
  background-color: #0D1721;
  border-color: #0D1721;
  margin-bottom: 0;
}

.topnav {
  font-size: 14px;
}

.lead {
  font-size: 18px;
  font-weight: 400;
}

.intro-header-homepage {
  text-align: center;
  color: #f8f8f8;
  background: url(http://imgur.com/20qY3EH.jpg) no-repeat;
  background-size: 100% 80%;
}

.intro-message {
  padding-top: 20%;
  padding-bottom: 20%;
}

.intro-message>h1 {
  margin: 0;
  text-shadow: 2px 2px 3px rgba(0, 0, 0, 0.6);
  font-size: 5em;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<!DOCTYPE html>
<html>

<head>
  <title></title>
</head>

<body>
  <!-- Navigation -->
  <nav class="navbar navbar-default navbar-sticky-top topnav" role="navigation">
    <div class="container topnav">
      <div class="navbar-header">
        <a class="navbar-brand topnav" href="#">Home</a>
      </div>
      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav navbar-right">
          <li>
            <a href="#">Imagery</a>
          </li>
          <li>
            <a href="#">Education and Outreach</a>
          </li>
          <li>
            <a href="index.html">Data Resources</a>
          </li>
        </ul>
      </div>
    </div>
  </nav>
  <div class="intro-header-homepage">
    <div class="container">
      <div class="row">
        <div class="col-lg-12">
          <div class="intro-message">
            <h1>Website Homepage</h1>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-lg-6 col-lg-offset-3">
      <p class="p-homepage">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    </div>
  </div>
</body>

</html>

JSFiddle