div stretch 100% page height regardless of content

守給你的承諾、 提交于 2019-12-19 08:12:48

问题


live (work in progress) site

Basically, I have all of my site's content centered within a div that is a specified width and an intended height of 100% regardless of the actual length of the content. I've specified height:100%; for html, body, and #main however the div still comes up short as seen on this page- I don't want their to be any gap between the #main's grey box and the bottom of the screen. Is this possible? How?


回答1:


see this jsfiddle

html, body {height: 100%;}
.container {min-height: 100%;}

discussing this over here too.....

proper css to ensure that the body element fills the entire screen




回答2:


You can set position:absolute, and that should stretch it to the bottom. Seems as if that will work fine in Opera and Chrome at least.

That will, however, be in conflict with the video player below, and also push your copyright notice down below the page. Maybe you can move the notice up into the gray box though?




回答3:


You can achieve by 2 ways:

1) Give Height to 100% if you don't know how long page could be.

html, body {
    height: 100%;
}
.yourContainerClass {
    min-height: 100%;
}

2) If you know how much you need to stretch vertically then you can use height in "vh(vertical height)".

.yourContainerClass{
    height:80vh;
}

I hope it will help you. Thank you!



来源:https://stackoverflow.com/questions/12043830/div-stretch-100-page-height-regardless-of-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!