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

Jennifer Hinkle
Jennifer Hinkle
8,365 Points

background color height

Hello,

I have a container div with very few elements in it so the content ends about half way up the viewport. Therefore, the background color ends at the bottom of my elements. Is there a way to get the div to fill the entire height of the browser so the background color fills the entire viewport?

html

<!DOCTYPE html>
<html>
    <body>
        <div class="container"> 
            <p>Hello World!</p>
       </div>
    </body>
</html

CSS

.container {
    background: tomato; 
    overflow: auto;
    width: 100%;
    height: 100%;
}

Thanks for any tips! Jenn

3 Answers

Hi, Have you tried setting the background on the body element? for example:

body {
  background: tomato;
}

Try this:

.container {
  background: tomato;
  width: 100%;
  height: 100%;
}

html, body {
    margin: 0;
    height: 100%;
}

Hope it helps!

Jennifer Hinkle
Jennifer Hinkle
8,365 Points

perfect! thanks so much for the tip!!

Jennifer,

Try changing "height" to "min-height", or applying color to the html or body tags.

Jennifer Hinkle
Jennifer Hinkle
8,365 Points

Thanks for the advice! But I'm applying the background color to the container instead of the body because I'm have the body act as a white border around my container. Also, maybe I'm using it wrong, but

min-height: 100%;

didn't change anything for me ...