我遇到了100%高度的老问题。我知道这个问题问了很多,我已经回顾了this,this,this和无数。我想创建一个基本固定的头,边导航和文章主要区域,看起来像这样:100%不工作(感觉真的很愚蠢)
但是,由于某种原因,它看起来像蓝条以下的(我把200像素填充刚让它出现)。
我的HTML如下所示:
<!DOCTYPE html>
<html>
<head></head>
<body>
<header></header>
<section>
<nav></nav>
<article></article>
</section>
</body>
</html>
我的CSS是这样的:
* { -moz-box-sizing: border-box; background-color: transparent; border: 0 none; color: #000000; list-style: none outside none; margin: 0; outline: medium none; padding: 0; text-decoration: none; }
body, html { height: 100%; }
header {
background: #6c6363;
top: 0;
z-index: 100;
height: 100px;
left: 0;
position: fixed;
right: 0;
}
section {
min-height: 100%;
overflow: auto;
position: relative;
padding-top: 100px;
}
nav {
background-color: #747feb;
float: left;
min-height: 100%;
padding-bottom: 200px;
width: 150px;
}
article {
background: #74eb8a;
margin: 20px 20px 20px 170px;
min-height: 100%;
padding: 20px;
position: relative;
}
正如你所看到的,没有什么太特别的。我知道section
需要100%的高度,body
和html
也是如此。我可以定位nav
和acticle
绝对,使这样的事情:
但是,在我的实际网站(我简化它这个),侧面导航具有下拉菜单,这将改变动态导航高度。这会导致以下情况发生:
绝对定位的元素不会改变相对包装的高度,所以我需要把它们飘浮。但是,漂浮它们并不会使高度达到100%。
我甚至做了的jsfiddle,借以说明问题:http://jsfiddle.net/g8VjP/
如果有人能帮助我,我真的很感激。
谢谢! PS:我都是使用calc(),如果它工作的话!
SOLUTION
我修改Mayank的答案,并设法拿出一个解决方案。我不得不添加一对夫妇包装,但它的工作。我的HTML现在看起来像下面这样:
<!DOCTYPE html>
<html>
<head></head>
<body>
<header></header>
<section>
<nav></nav>
<div class="cell-wrap">
<div class="table-wrap">
<article></article>
</div>
</div>
</section>
</body>
</html>
随着键为cell-wrap
和table-wrap
。我有nav
是一个表格单元,.cell-wrap
是另一个。随着nav
有固定的,.cell-wrap
填补其余。但是,我希望在article
附近放置空格,所以我添加了.table-cell
并将其放入表中。然后扩大并填充.cell-wrap
的高度和宽度。然后,我添加30px填充以在article
周围给出空格(因为页边单元格上的页边空白不起作用)并将article
设置为表格单元格。
有点混淆,但它的工作原理!
我的CSS如下:
* { -moz-box-sizing: border-box; background-color: transparent; border: 0 none; color: #000000; list-style: none outside none; margin: 0; outline: medium none; padding: 0; text-decoration: none; }
body, html { height: 100%; }
header {
background: #6c6363;
top: 0;
z-index: 100;
height: 100px;
left: 0;
position: fixed;
right: 0;
}
section {
display: table;
height: 100%;
min-height: 100%;
padding-top: 100px;
position: relative;
width: 100%;
}
nav {
background-color: #657182;
display: table-cell;
min-height: 100%;
width: 150px;
}
.cell-wrap {
display: table-cell;
height: 100%;
min-height: 100%;
}
.table-wrap {
display: table;
height: 100%;
padding: 30px;
width: 100%;
}
article {
background: none repeat scroll 0 0 #FFFFFF;
display: table-cell;
min-height: 100%;
padding: 20px 20px 120px;
z-index: 1;
}
Here's the fiddle。不知道为什么在底部有一个滚动条,但如果你在浏览器中正常显示它,看起来很好。
下面是一个[示例](http://jsfiddle.net/AxEPc/1)。 [caniuse calc()](http://caniuse.com/calc) – Vucko