gpt4 book ai didi

css - 用CSS填充剩余的屏幕高度

转载 作者:行者123 更新时间:2023-12-02 05:11:57 25 4
gpt4 key购买 nike

我正在建立一个具有3个div的页面布局:一个具有固定高度(以像素为单位)的页眉和页脚,以及一个位于页面中间的内容div,应填充剩余的屏幕高度。此外,我希望能够在内部内容div中将高度设置为100%,因为其中一个将承载一种需要填充其余屏幕高度的绘图区域。因此,内部div不要在页眉或页脚下泄漏特别重要。到目前为止,我实现了100%有效的CSS解决方案,该解决方案可以在除Internet Explorer 6和7之外的所有主要浏览器中使用。

我可以做些什么来修复IE6和7的布局吗?或者,您是否看到另一种做我想要的方式?

这是代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The #content div fill the remaining height and appears to have a height</title>
<style TYPE="text/css">
<!--
* {
margin: 0;
padding: 0;
}

html, body,
#container{
height: 100%;
}

#container{
position: relative;
}

#header,
#footer{
height: 60px;
line-height: 60px;
background: #ccc;
text-align: center;
width : 100%;
position: absolute;
}

#header{
top: 0;
}

#footer{
bottom: 0;
}

#content{
position: absolute;
top:60px;
bottom: 60px;
width : 100%;
overflow: auto;
border-top: 1px solid #888;
border-bottom: 1px solid #888;
}

#inner-content{
overflow: auto;
background-color: #FC0;
height: 100%;
}

p{
margin-bottom: 10px;
}
-->
</style>

</head>
<body>
<div id="container">
<div id="header">
<h1>Header</h1>
</div>
<div id="content">
<div id='inner-content'>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis turpis vel
quam dictum hendrerit eu non elit. Donec ultricies ullamcorper libero a molestie.
Donec auctor nulla vitae tortor ullamcorper posuere. Etiam fringilla tristique blandit.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis turpis vel
quam dictum hendrerit eu non elit. Donec ultricies ullamcorper libero a molestie.
Donec auctor nulla vitae tortor ullamcorper posuere. Etiam fringilla tristique blandit.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis turpis vel
quam dictum hendrerit eu non elit. Donec ultricies ullamcorper libero a molestie.
Donec auctor nulla vitae tortor ullamcorper posuere. Etiam fringilla tristique blandit.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis turpis vel
quam dictum hendrerit eu non elit. Donec ultricies ullamcorper libero a molestie.
Donec auctor nulla vitae tortor ullamcorper posuere. Etiam fringilla tristique blandit.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis turpis vel
quam dictum hendrerit eu non elit. Donec ultricies ullamcorper libero a molestie.
Donec auctor nulla vitae tortor ullamcorper posuere. Etiam fringilla tristique blandit.
</p>
</div>
</div>
<div id="footer">
<h1>Footer</h1>
</div>
</div>
</body>
</html>

在此先感谢您的帮助。

Live example here

最佳答案

我最终使用Javascript实现了同样的事情

关于css - 用CSS填充剩余的屏幕高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4954997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com