将 html 元素设置为带标题的页面高度为 100%
如何在具有固定高度标题的页面上将 html 元素设置为 100% 高度?当然,布局的高度不是固定的。
我已经将 html
和 body
设置为正确模拟 min-height: 100%
。
我已经尝试过以下想法,但无济于事:
1.我使用了以下CSS,但它使用基于百分比的高度,这效果不佳,因为我的布局的标题是固定的81px高度。
#divContent
{
height: 82%;
margin: 0;
padding: 0;
position: absolute;
top: 82px;
width: 950px;
}
2.我在填充和边距的各种组合中使用了以下内容,但它们都扩展了页面的高度(这是隐藏
),从而使它们全部看起来一样:底部 81px
被隐藏。
html, body
{
overflow: hidden;
margin-bottom: 82px;
padding-bottom: 82px;
}
#divContent
{
height: 100%;
margin: 0;
padding: 0;
position: absolute;
top: 82px;
width: 950px;
margin-bottom: 82px;
padding-bottom: 82px;
}
我希望我的 divContent
消耗掉主体的所有高度减去 81px
。
我知道如何立即使用表格来完成此操作,但这将是对表格的不当使用。我还认为它可以使用 jQuery 自动计算,但我以前没有写过这样的 jQuery。
PS我已经浏览了大约十几个问题,但找不到解决方案。如果您可以证明这是实际上涵盖同一问题的重复内容,我很乐意阅读另一篇文章。
How can I set an html element to have a 100% height on a page that has a fixed height header? The layout is, of course, not fixed height.
I already have the html
and body
set to simulate min-height: 100%
correctly.
I have tried the following ideas, but to no avail:
1. I have used the following CSS, but it uses a percentage-based height, which doesn't work well because my layout's header is a fixed 81px
in height.
#divContent
{
height: 82%;
margin: 0;
padding: 0;
position: absolute;
top: 82px;
width: 950px;
}
2. I have used the following in various combinations of the padding and margin, but all of them expand the height of the page (which is hidden
), thereby making them all look the same: the bottom 81px
are hidden.
html, body
{
overflow: hidden;
margin-bottom: 82px;
padding-bottom: 82px;
}
#divContent
{
height: 100%;
margin: 0;
padding: 0;
position: absolute;
top: 82px;
width: 950px;
margin-bottom: 82px;
padding-bottom: 82px;
}
I want my divContent
to consume all of the body's height minus 81px
.
I know how I could immediately do it using tables, but that would be improper use of tables. I also figure that it could be automatically calculated using jQuery, but I haven't written jQuery like that before.
P.S. I have looked through about a dozen questions and cannot find a solution. If you can prove this is a duplicate that actually covers the same issue, I would gladly read that other post.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 div 的底部设置为 0px。这将扩展 div 以消耗页面的其余部分
这是我不久前回答的一个非常类似的问题
如何使用 CSS 构建此布局?
Set the bottom of the div to 0px. This will expand the div to consume the rest of the page
Here is a very similar question I answered a while back
How to build this layout with CSS?