Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

How to make a div extend the full screen

I've tried to make it work many ways for the last couple of hours but haven't been able to make it work through all browsers correctly. What I'm trying to do is extend a container div background all the way to the bottom of the page, even if there's not enough content.

<html>
  <head>
  </head>

  <body>
    <div class="container">
      <div class="content">
        <p>blah blah blah</p>
      </div>
    </div>
  </body>

</html>
html,
body,
.container {
  height: 100%;
  margin: 0;
}
body {
  background: steelblue;
}
.container {
  background: gray;
  margin-bottom: 2em;
}

2 Answers

Looks like it works to me http://codepen.io/jamesbarnett/pen/japLE

Hello James.

I was just wondering why the browser adds an extra space above the .container div, and how to remove it.

I was experimenting with the code and I could remove it by:

  • setting the margin-top to 0 on the p element
  • setting the width property of .container to 100% and its position to absolute

However, I would like to fully understand this problem.

I hope you can reply. Thanks.

The issue is that there's no content above your <p> so it's margin pushes it down, you're right about <p> tags do having margin removing the top margin in cases like this solves the issue.