所以我有一个包含页眉、主体和页脚的网页。我希望主体填充100%的页面(填充100%在页脚和页眉之间)我的页脚是位置绝对与底部: 0。每次我尝试将主体设置为100%高度或改变位置或其他什么,它也会溢出标题。如果使用top: 40
将正文设置为绝对位置(因为我的标题是40px高),它就会太低40px,从而创建一个滚动条。
我创建了一个简单的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>
有人知道答案吗?
发布于 2014-12-20 05:21:25
有一个名为视口高度/视口宽度的CSS单位。
示例
类似于html,body{width: 100vw;}
的.mainbody{height: 100vh;}
或90vh =视口高度的90%。
**IE9+和大多数现代浏览器。
发布于 2013-09-07 03:46:07
这使得内容主体居中,宽度最小,使我的表单不会滑稽地折叠:
html {
overflow-y: scroll;
height: 100%;
margin: 0px auto;
padding: 0;
}
body {
height: 100%;
margin: 0px auto;
max-width: 960px;
min-width: 750px;
padding: 0;
}
div#footer {
width: 100%;
position: absolute;
bottom: 0;
left: 0;
height: 60px;
}
div#wrapper {
height: auto !important;
min-height: 100%;
height: 100%;
position: relative;
overflow: hidden;
}
div#pageContent {
padding-bottom: 60px;
}
div#header {
width: 100%;
}
我的布局页面看起来像这样:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
</head>
<body>
<div id="wrapper">
<div id="header"></div>
<div id="pageContent"></div>
<div id="footer"></div>
</div>
</body>
</html>
示例如下:http://data.nwtresearch.com/
另请注意,如果您想要像添加的代码那样的整个页面背景,请从包装器div:http://jsfiddle.net/mdares/a8VVw/中删除height: auto !important;
发布于 2013-09-07 03:37:18
使用没有定义高度的top: 40px
和bottom: 40px
(假设你的页脚也是40px),你可以让它工作。
.header {
width: 100%;
height: 40px;
position: absolute;
top: 0;
background-color:red;
}
.mainBody {
width: 100%;
top: 40px;
bottom: 40px;
position: absolute;
background-color: gray;
}
.footer {
width: 100%;
height: 40px;
position: absolute;
bottom: 0;
background-color: blue;
}
https://stackoverflow.com/questions/18665171
复制相似问题