Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 ...