how do I set height of container DIV to 100% of window 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


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.


Did you set the CSS:

html, body
{
    height: 100%;
}

You need this to be able to make the div take up all the space. :)


你可以将它设置为查看高度

html, body
{
    height: 100vh;
}
链接地址: http://www.djcxy.com/p/89400.html

上一篇: 将HTML和BODY选择器样式设置为高度:100%; vs使用100vh

下一篇: 如何将容器DIV的高度设置为窗口高度的100%?