我有一个包含页头(header)、主体(mainbody)和页脚(footer)的网页。我想让主体充满整个页面(在页头和页脚之间填充100%)。
我的页脚被设置为绝对定位,带有bottom:0的属性。每次我尝试将主体设置为100%高度或更改其位置时,它也会溢出页头。如果我将主体设置为绝对定位,并指定top:40(因为我的页头高度为40px),它会向下移动40像素,从而创建一个滚动条。
鉴于实际项目中无法发布整个页面/ CSS,我创建了一个简单的HTML文件。使用样例代码,即使主内容区域填充了整个屏幕,它也会向下移动40px(我猜是由于页头导致的)。
html,
body {
margin: 0;
padding: 0;
}
header {
height: 40px;
width: 100%;
background-color: blue;
}
#maincontent {
background-color: green;
height: 100%;
width: 100%;
}
footer {
height: 40px;
width: 100%;
background-color: grey;
position: absolute;
bottom: 0;
}
<html>
<head>
<title>test</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<header></header>
<div id="maincontent">
</div>
<footer></footer>
</body>
</html>
有人知道答案吗?