【发布时间】:2016-05-01 21:16:43
【问题描述】:
我尝试创建 div 页脚,但有问题。
我在容器内一一放置了几个 div 块。 容器有 100% 的高度。 Container First Div 内部有 100px 的高度(标题)。 Second Div (Mainbody) 的所有高度都必须达到站点底部(屏幕尺寸的 bootom 部分)或更高。
第三格有绝对位置,位于底部。 但 Container Div 的摘要高度超过 100%,因为我在页面右侧看到滚动。 如何解决?
具有 css: height:100% 的页面占用超过 100%
html, body {
height: 100%;
margin:0;
padding:0;
background-color: yellow;
}
.container {
position:relative;
min-height:100%;
background-color: green;
}
.header {
background-color: blue;
height: 100px;
}
.mainbody {
background-color: gray;
height: 100px;
}
.footer {
position:absolute;
bottom:0;
width: 100%;
background-color: red;
}
<body>
<div class="container">
<div class="header">
<p>
header
</p>
</div>
<div class="mainbody">
<p>
mainbody
</p>
</div>
<div class="footer">
<p>
footer
</p>
</div>
</div>
</body>
【问题讨论】:
-
你试过
position:fixed作为页脚吗? -
这听起来像你想把页脚粘在页面底部?如果是这样,Google
sticky footer有几种方法可以做到这一点