Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I set height of container DIV to 100% of window height?

Tags:

css

height

I have a couple of problems with my container DIV. For one it is not recognising the height of my content correctly (I would have thought it would extend beyond the bottom of the main content and sidebar, but it isn't). You can see what I mean on this page.

I would also like the container DIV to always fill the available height of the screen/window. I have tried setting it to min-height:100%, but this didn't have any effect.

Here is the CSS I am using for the container DIV:

#container {   padding: 0;   margin: 0;   background-color: #292929;   width: 1200px;   margin: 0 auto;   min-height: 100%; } 

I would be grateful for any help to get this working.

Thanks,

Nick

like image 895
Nick Avatar asked Dec 12 '11 10:12

Nick


People also ask

What does height 100% do CSS?

height: 100% gives the element 100% height of its parent container. height: auto means the element height will depend upon the height of its children.

How do I change the full page height in CSS?

For a responsive full page height, set the body element min-height to 100vh. If you set a page width, choose 100% over 100vw to avoid surprise horizontal scrollbars.


2 Answers

Add this to your css:

html, body {     height:100%; } 

If you say height:100%, you mean '100% of the parent element'. If the parent element has no specified height, nothing will happen. You only set 100% on body, but you also need to add it to html.

like image 170
ptriek Avatar answered Sep 21 '22 11:09

ptriek


You can net set it to view height

html, body {     height: 100vh; } 
like image 45
Nicky Thomas Avatar answered Sep 20 '22 11:09

Nicky Thomas