所以我有一个包含页眉、主体和页脚的网页。
我希望主体填充页面的100% (在页脚和页眉之间填充100%)
My footer is position absolute with bottom: 0. Everytime I try to set the mainbody to 100% height or change position or something it will also overflow the header. If if set the body to position absolute with top: 40
(cause my header is 40px high), it will just go 40px too far down, creating a scroll bar.
我创建了一个简单的 html 文件,因为我实际上不能从实际的项目中发布整个页面/css。对于示例代码,即使主内容主体填满了屏幕,它也会向下延伸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>
有人知道答案吗?