【发布时间】:2014-09-19 17:10:14
【问题描述】:
我创建了一个 html 文件,其中包含页眉 div、内容 div 和页脚 div。 “bodyDiv”标签应该会出现滚动条(确实如此)。
现在我的问题是:为什么“bodxDiv”内的内容大于屏幕高度?所以滚动条出现了 - 如果不需要它。
在图片中可以看到,内容在红线之后结束,但还是有滚动条
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="bodyDiv">
<div id="mainDiv">
<div id="headDiv">Header</div>
<div id="contentDiv">Content</div>
<div id="footerDiv">Footer</div>
</div>
</div>
</body>
</html>
style.css
<style type="text/css">
* {
margin: 0;
padding: 0;
}
html *
{
color: #000;
font-family: "Arial", Arial, sans-serif;
}
body, html {
width: 100%;
height: 100%;
overflow: hidden;
}
#bodyDiv {
position: absolute;
top: 0;
left: 0;
z-index: 2;
overflow: auto;
width: 100%;
height: 100%;
text-align: center;
}
#mainDiv {
width: 600px;
height: 100%;
text-align: left;
margin: 18px auto;
}
#headDiv {
border: 1px solid #000;
}
#contentDiv {
border: 1px solid #000;
margin-top: 6px;
}
#footerDiv {
border: 1px solid #000;
margin-top: 6px;
}
</style>
【问题讨论】:
-
这里是 OP 的代码jsfiddle.net/9YgLh/1
-
#mainDiv的高度为 100%和上下边距。