【发布时间】:2018-12-26 17:48:32
【问题描述】:
我想在更大的 CSS 网格布局中集成像 https://jsfiddle.net/przemcio/xLhLuzf9/3/ 这样的布局。但是,一旦容器具有属性display: grid,一切都会中断。 “中断”是指 .content div 所需的 flexbox 收缩属性不适用,它不会收缩并允许页脚的内容显示在滚动折叠上方。
这是一个准系统演示,但在我更大的应用程序中存在相同的行为。为什么 CSS Grid 会破坏这种布局,即使在子单元格内部也是如此,我该如何解决?
演示:
html,
body {
height: 100%;
margin: 0
}
.grid {
/* this line breaks it: */
display: grid;
height: 100vh;
}
.cell {
height: 100%;
display: block;
grid-column-end: span 1;
grid-row-end: span 1;
}
.box {
display: flex;
flex-flow: column;
height: 100%;
}
.content {
flex: 1 1 auto;
overflow-y: auto;
border-bottom: 1px solid gray;
}
.footer {
flex: 0 1 auto;
}
<!DOCTYPE html>
<html>
<body>
<div class="grid">
<div class="cell">
<div class="box">
<div class="content">
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
<p>
<b>content</b> (fills remaining space)
</p>
</div>
<div class="footer">
<p><b>footer</b>
<br>
<br>(sized to content)</p>
</div>
</div>
</div>
</div>
</body>
</html>
【问题讨论】: