DIV 100% 高度,带页脚和页眉,动态
DIV 100% height with footer and header, dynamic
我已经搜索了几个小时来寻找 100% 高度 div 问题的良好解决方案。我现在尝试了不同的代码,但其中一些并没有真正帮助(对我而言),因为我需要一个响应迅速且支持 IE8+ 的解决方案。所以一些有用的标签,比如 'calc()' 函数或 'flexbox' 是无效的。
我创建了一个 sample page 来向您展示问题所在。页脚应该在当前大小的 window 的底部。两个内容 div 都应具有当前内容屏幕的完整高度,并且不应有任何滚动条,只要内容超过当前屏幕即可。如果内容超出当前屏幕高度,页脚不应固定,应移动 "down"。
我的页面是响应式的,并且使用 Bootstrap3 构建。所以有更多的行和列,但基本构建如下所示。
当前页面构建如下:
<div id="page">
<div id="header">
My menu
</div>
<div id="content">
<div class="" id="content_left">
Some content here ...
</div>
<div id="content_right">
Some content there ...
</div>
</div>
<div id="footer">
My footer
</div>
</div>
CSS:
html, body
{
display: block;
min-height:100%;
height: 100%;
padding:0;
margin:0;
}
#page
{
margin: auto;
max-width:500px;
min-height: 100%;
height: 100%;
background: #333;
}
#header
{
padding: 20px;
background: #FF0;
}
#footer
{
padding: 20px;
background: #F0F;
clear: both;
}
#content_left
{
background: #0F0;
float: left;
width: 25%;
}
#content_right
{
background: #0FF;
width: 65%;
float: left;
}
#content_left, #content_right
{
padding: 10px;
}
抱歉有那么多条件,但这是我必须适应的环境。 (-;
此致,
滑雪
你可以考虑按如下方式进行
检查这个片段
html,
body {
width: 100%;
height: 100%;
margin: 0px;
}
#page {
margin: auto;
width: 500px;
position: relative;
height: 100%;
background: #333;
}
#wrapper {
height: 100%;
background: #A00;
}
#header {
padding: 20px;
background: #FF0;
}
#content_left {
display: table-cell;
background: #0F0;
width: 25%;
}
#content_right {
display: table-cell;
background: #0FF;
width: 75%;
}
#content_left,
#content_right {
padding: 10px;
}
#footer {
background: orange;
display: table-cell;
width: 500px;
}
<div id="page">
<div id="wrapper">
<div id="header">
My menu
</div>
<div id="content">
<div class="" id="content_left">
Some content here ...
</div>
<div id="content_right">
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there.
<br />Some content there.
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />
</div>
</div>
<div id="footer">
My footer
</div>
</div>
</div>
希望对您有所帮助
谢谢你的建议,我已经解决了问题。
我制作了一个包含 Bootstrap 3 框架的新 CodepenIO。
对于解决方案本身,我已将页脚排除在包装之外。表示主容器的内容是包装器 DIV(包括所有内容)和页脚 DIV(包括页脚)。对于包装器的底部元素,我添加了一个 padding-bottom 属性,并为页脚本身添加了一个 minus margin-top 属性,它等于页脚的高度。所以页脚向上移动,如果内容不会导致分页,如果内容太多,页脚向下移动。您可以找到解决方案本身 HERE.
HTML 如下所示:
<div class="container">
<div class="" id="wrapper">
<div class="row" id="header">
<div class="">My menu</div>
</div>
<div class="row" id="content">
<div class="col-lg-4 col-sm-4" id="content_left">
Some content here ...
</div>
<div class="col-lg-8 col-sm-8" id="content_right">
Some content there...
</div>
</div>
<div style="clear:both;"></div>
</div>
<div class="row" id="footer">
<div>My footer</div>
</div>
</div>
和CSS:
html,body
{
width:100%;
height:100%;
}
.container
{
display: table;
height: 100%;
min-height:100%;
max-width: 500px;
background: #333;
}
#wrapper
{
height: 100%;
min-height: 100%;
background: #A00;
}
.content
{
background: #A00;
}
#header
{
padding: 20px;
background: #FF0;
}
#footer
{
clear: both;
background: #F0F;
min-height: 20px;
margin-top: -20px;
}
#content_left
{
background: #0F0;
}
#content_right
{
background: #0FF;
}
#content_left,
#content_right
{
padding-bottom: 20px;
}
非常感谢您的帮助! (-:
我已经搜索了几个小时来寻找 100% 高度 div 问题的良好解决方案。我现在尝试了不同的代码,但其中一些并没有真正帮助(对我而言),因为我需要一个响应迅速且支持 IE8+ 的解决方案。所以一些有用的标签,比如 'calc()' 函数或 'flexbox' 是无效的。
我创建了一个 sample page 来向您展示问题所在。页脚应该在当前大小的 window 的底部。两个内容 div 都应具有当前内容屏幕的完整高度,并且不应有任何滚动条,只要内容超过当前屏幕即可。如果内容超出当前屏幕高度,页脚不应固定,应移动 "down"。
我的页面是响应式的,并且使用 Bootstrap3 构建。所以有更多的行和列,但基本构建如下所示。
当前页面构建如下:
<div id="page">
<div id="header">
My menu
</div>
<div id="content">
<div class="" id="content_left">
Some content here ...
</div>
<div id="content_right">
Some content there ...
</div>
</div>
<div id="footer">
My footer
</div>
</div>
CSS:
html, body
{
display: block;
min-height:100%;
height: 100%;
padding:0;
margin:0;
}
#page
{
margin: auto;
max-width:500px;
min-height: 100%;
height: 100%;
background: #333;
}
#header
{
padding: 20px;
background: #FF0;
}
#footer
{
padding: 20px;
background: #F0F;
clear: both;
}
#content_left
{
background: #0F0;
float: left;
width: 25%;
}
#content_right
{
background: #0FF;
width: 65%;
float: left;
}
#content_left, #content_right
{
padding: 10px;
}
抱歉有那么多条件,但这是我必须适应的环境。 (-;
此致, 滑雪
你可以考虑按如下方式进行
检查这个片段
html,
body {
width: 100%;
height: 100%;
margin: 0px;
}
#page {
margin: auto;
width: 500px;
position: relative;
height: 100%;
background: #333;
}
#wrapper {
height: 100%;
background: #A00;
}
#header {
padding: 20px;
background: #FF0;
}
#content_left {
display: table-cell;
background: #0F0;
width: 25%;
}
#content_right {
display: table-cell;
background: #0FF;
width: 75%;
}
#content_left,
#content_right {
padding: 10px;
}
#footer {
background: orange;
display: table-cell;
width: 500px;
}
<div id="page">
<div id="wrapper">
<div id="header">
My menu
</div>
<div id="content">
<div class="" id="content_left">
Some content here ...
</div>
<div id="content_right">
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there ...
<br />Some content there.
<br />Some content there.
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />Some content there ...
<br />Some content there.
<br />
</div>
</div>
<div id="footer">
My footer
</div>
</div>
</div>
希望对您有所帮助
谢谢你的建议,我已经解决了问题。 我制作了一个包含 Bootstrap 3 框架的新 CodepenIO。
对于解决方案本身,我已将页脚排除在包装之外。表示主容器的内容是包装器 DIV(包括所有内容)和页脚 DIV(包括页脚)。对于包装器的底部元素,我添加了一个 padding-bottom 属性,并为页脚本身添加了一个 minus margin-top 属性,它等于页脚的高度。所以页脚向上移动,如果内容不会导致分页,如果内容太多,页脚向下移动。您可以找到解决方案本身 HERE.
HTML 如下所示:
<div class="container">
<div class="" id="wrapper">
<div class="row" id="header">
<div class="">My menu</div>
</div>
<div class="row" id="content">
<div class="col-lg-4 col-sm-4" id="content_left">
Some content here ...
</div>
<div class="col-lg-8 col-sm-8" id="content_right">
Some content there...
</div>
</div>
<div style="clear:both;"></div>
</div>
<div class="row" id="footer">
<div>My footer</div>
</div>
</div>
和CSS:
html,body
{
width:100%;
height:100%;
}
.container
{
display: table;
height: 100%;
min-height:100%;
max-width: 500px;
background: #333;
}
#wrapper
{
height: 100%;
min-height: 100%;
background: #A00;
}
.content
{
background: #A00;
}
#header
{
padding: 20px;
background: #FF0;
}
#footer
{
clear: both;
background: #F0F;
min-height: 20px;
margin-top: -20px;
}
#content_left
{
background: #0F0;
}
#content_right
{
background: #0FF;
}
#content_left,
#content_right
{
padding-bottom: 20px;
}
非常感谢您的帮助! (-: