我有一个两列布局:
<html>
<head></head>
<body>
<div id="container">
<div id="header"></div>
<div id="sidewrapper"></div>
<div id="contentwrapper"></div>
</div>
</body>
</html>
我想让侧边栏和内容的高度均为 100%,但最顶部容器的最小高度应为 100%。
我试图用下面的 css 来解决它:
* {
margin: 0;
padding: 0;
}
html {
font-family: Georgia, serif;
color: #000; height:100%; min-height:100px;
}
body {
background: #fff; height:100%; min-height:100px; overflow:hidden;
}
#header {
width: 100%;
position: relative;
float: left;
height: 23px;
}
#container {
position:relative;
width: 100%; height:100%;
margin: auto; background:blue;
}
#contentwrapper {
float:left;
background:red;
position: relative;
width: 700px; padding:0px; margin:0px;
height: auto;
}
#sidewrapper {
float:left;
position: relative;
width: 159px; height:100%;
padding:0px; margin:0px;
}
…但是由于标题的 23px 高度,我得到了一个滚动条。我试图用 body 元素的 overflow:hidden 来解决它,但我不知道这是否是正确的解决方案。
有任何想法吗?
原文由 DarkLeafyGreen 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果我在对问题的评论中提出的假设是正确的,那么
sidebar
是100%
高,最重要的是你有一个23px
使您的容器成为100%
+23px
高。将来你将拥有 css
calc()
http://hacks.mozilla.org/2010/06/css3-calc/ 。这将解决您的问题。现在,我猜你应该通过 javascript 计算侧边栏的高度(=容器的高度 - 23px)。