gpt4 book ai didi

css - 页面高度-div结构

转载 作者:行者123 更新时间:2023-11-27 22:48:58 24 4
gpt4 key购买 nike

我试图让我的页面占据 100% 的屏幕,并带有页脚,它需要始终位于页面底部。

div 应该在页面调整大小时展开,并具有正确的背景颜色。

我目前的错误是:- 页脚位于屏幕底部而不是页面底部。- div(菜单)大于 div(内容)- div 未正确调整大小

这是我的代码:

div结构

<div id="container"><br />
<div id="header">CMS</div>

<div id="menu"><?php include ('includes/menu.php');?></div>
<div id="content">
<?php include $include_page?>
</div>

<div id="footer">CMS</div>
</div>

CSS

body {
height: 100%;
color: #0b0b0b;
background-color: #696060;
margin: 0px;
padding: 0px;
font-family: Tahoma, sans-serif;
font-size: 12.5px;
}

#container {
margin-left: auto;
margin-right: auto;
width: 1000px;
background-color: #f1f1f1;
border-left: 1px solid #8f8f8f;
border-right: 1px solid #8f8f8f;
height: 100%;
}
#header {
height: 100px;
width: 100%;
background-color: #a31f00;
color: #fcfcfc;
text-align: center;
}
#menu {
width: 210px;
background-color: #e0e0e0;
float: left;
padding: 10px 10px 10px 10px;
height: 100%;
}
#content {
width: 750px;
height: 100%;
float: left;
padding: 10px 10px 10px 10px;
}
#footer {
position: absolute;
bottom: 0;
width: 1000px;
height: 20px;
background-color: #a31f00;
color: #fcfcfc;
text-align: center;
font-size: 11px;
}

最佳答案

您可能正在考虑粘性页脚。当没有足够的内容将其向下推时,粘性页脚会粘在页面底部,但当内容开始溢出页面时,它会随之溢出。

要制作一个,您基本上想要将页脚以外的所有内容包装在 <div> 中标签,像这样:

<div id="wrap">
<div id="header">
...
</div>

<div id="main">
<!-- All you page content goes here -->
</div>
</div>

<div id="footer">
I am a footer.
</div>

现在,对于神奇的 CSS:

html, body
{
height: 100%;
}

#wrap
{
min-height: 100%;
}

#main
{
overflow: auto;
padding-bottom: 150px; /* must be same height as the footer */
}

#footer
{
position: relative;
margin-top: -150px; /* negative value of footer height */
height: 150px;
clear: both;
}

/* Opera Fix */
body:before
{
content: "";
height: 100%;
float: left;
width: 0;
margin-top: -32767px;/
}

在您的 HTML 页面上,您将需要针对 IE6 和更早版本以及 IE8 的条件样式(!IE7 表示不是 7,而是所有其他):

<head>
...
<!--[if !IE 7]>
<style type="text/css">
#wrap
{
display: table;
height: 100%;
}
</style>
<![endif]-->
...
</head>

关于css - 页面高度-div结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5261939/

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