【发布时间】:2016-12-15 04:47:47
【问题描述】:
我使用 flexbox 让我的页脚停留在底部,仅当内容比视口短时。如果它更高,页脚应位于内容下方,因此您必须滚动才能看到它。
这在 Firefox 和 Edge 中可以正常工作,但在 Chrome 或 IE 中不能正常工作。
如您所见,在 Chrome 中,使视口短于内容会使页脚“卡在”视口底部。如果然后滚动,您会看到页脚向上滚动页面。
我认为问题出在 contentContainer 中:
#contentContainer {
display: flex;
flex-direction: column;
overflow: auto;
height: 100%;
width: 100%;
}
这个 div 包含内容和页脚,因此它可以有滚动条而不是内容本身。不过,我不确定它有什么问题。
html,
body,
#app {
padding: 0;
margin: 0;
}
#app,
#appContainer {
display: flex;
flex-direction: column;
height: 100vh;
}
#header {
background-color: #dddddd;
width: 100%;
min-height: 36px;
height: 36px;
display: flex;
flex-direction: row;
}
#contentContainer {
display: flex;
flex-direction: column;
overflow: auto;
height: 100%;
width: 100%;
}
#content {
display: flex;
flex-direction: column;
flex: 1;
}
#footer {
display: flex;
flex-direction: row;
background-color: #dddddd;
height: 20px;
min-height: 20px;
width: 100%;
}
<div id="app">
<div id="appContainer">
<div id="header">Header</div>
<div id="contentContainer">
<div id="content">
<p>Content</p>
<p>Content</p>
<p>Content</p>
<p>Content</p>
<p>Content</p>
</div>
<div id="footer">Footer</div>
</div>
</div>
</div>
演示JSFiddle.
【问题讨论】: