我已经在StackOverflow和网上查找了所有min-height:100%的解决方案,但似乎没有一个符合我的(相对简单)需求。
这是我想要实现的:
- 我有一个两列容器,两列都应该拉伸到相等的高度。
- 当内容不填充屏幕时,列应该拉伸到整个窗口的高度。
- 我很乐意使用flex-box,但如果可能的话,我更愿意不使用JS hack。
示例代码:
http://codepen.io/anon/pen/dwgDq?editors=110
<!DOCTYPE html>
<html>
<body>
<div class="container">
<div class="nav">
<p>Item 1</p>
<p>Item 2</p>
<p>Item 3</p>
<p>Item 4</p>
<p>Item 5</p>
</div>
<div class="content">
<p>Content 1</p>
<p>Content 2</p>
<p>Content 3</p>
<p>Content 4</p>
<p>Content 5</p>
<p>Content 6</p>
<p>Content 7</p>
<p>Content 8</p>
</div>
</div>
</body>
</html>
html, body { height: 100%; margin: 0; }
.wrapper {
height: 100%;
overflow: auto;
-webkit-overflow-scrolling: touch;
}
.container {
display: flex;
align-items: stretch;
min-height: 100%;
}
.nav {
background: grey;
width: 200px;
}
.content {
flex-grow: 1;
background: yellow;
}
在 Safari 和 Chrome 中,这个方案能够完美地工作。
看起来 IE(在我的情况下是 v11)并不遵守我的 min-height,因此,列并没有填满屏幕的高度。从我所阅读的内容来看,IE6+7 在处理 height 作为 min-height 方面存在问题,但是当使用 HTML5 doctype 时,这已经是过去的事情了。
我该如何让 IE 遵守我的 min-height?
我该如何使这个布局生效?