我目前正在开发一个简单的CSS布局,它由两个并排放置的窗格和一个页脚组成。我有以下限制:
我试图使用flexbox制作合适的东西。 A working example can be found on jsfiddle.
HTML:
<div class="container">
<div class="top">
<div class="left">
Top-left content
</div>
<div class="right">
<div class="rightInternal">
Large content goes here.
</div>
</div>
</div>
<div class="bottom">
Bottom pane content should not collapse or be pushed outside the bounds of 'container'.
</div>
</div>
CSS:
.container {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: stretch;
}
.top {
width: 100%;
flex-grow: 1;
display: flex;
flex-direction: row;
align-items: stretch;
}
.left {
width: 30%;
min-width: 30%;
}
.right {
flex-grow: 1;
overflow-y: auto;
}
.rightInternal {
display: flex;
flex-direction: column;
}
.bottom {
padding: 10px;
flex-shrink: 0;
display: flex;
justify-content: flex-end;
}
问题:
这在Chrome中运行良好,但内容在&#39; top&#39;超出了容器的范围。在IE和FF中由于内容很大。在&#39; top&#39;的内容上设置高度导致页脚被推离底部(高度:100%)或内容未扩展以填充可用的垂直空间(例如,高度:100px)。
如何创建所需的布局?
注意:
答案 0 :(得分:0)
我认为您可以通过将overflow
属性添加到.top
将overflow
设为hidden
.container {
width: 90%;
height: 300px;
background: rgba(255, 125, 125, 1);
padding: 10px;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: stretch;
}
.top {
width: 100%;
background: rgba(238, 130, 238, 1);
flex-grow: 1;
display: flex;
flex-direction: row;
align-items: stretch;
overflow: hidden;
}
.left {
width: 30%;
min-width: 30%;
background: rgba(135, 206, 250, 1);
padding: 10px;
margin: 10px;
}
.right {
background: rgba(152, 251, 152, 1);
padding: 10px;
margin: 10px;
flex-grow: 1;
overflow-y: auto;
}
.rightInternal {
display: flex;
flex-direction: column;
}
.bottom {
background: rgba(255, 255, 153, 1);
padding: 10px;
flex-shrink: 0;
display: flex;
justify-content: flex-end;
}
&#13;
<div class="container">
<div class="top">
<div class="left">
Top-left content
</div>
<div class="right">
<div class="rightInternal">
This rainbow should scroll!
<br/>
<br/>
<div style="background-color:red;height:60px">Richard</div>
<div style="background-color:orange;height:60px">of</div>
<div style="background-color:yellow;height:60px">York</div>
<div style="background-color:green;height:60px">gained</div>
<div style="background-color:blue;height:60px">battle</div>
<div style="background-color:indigo;height:60px">in</div>
<div style="background-color:violet;min-height:60px">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in congue ipsum. Suspendisse maximus non magna sed blandit. Fusce mattis nisl elit, a sollicitudin justo porta ac. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices
posuere cubilia Curae; Donec elementum nunc ac vehicula dictum. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla ultricies ipsum dignissim quam venenatis, in vehicula eros ultrices. Maecenas ut malesuada
nulla.
</div>
</div>
</div>
</div>
<div class="bottom">
Bottom pane content should not collapse or be pushed outside the bounds of 'container'.
</div>
</div>
&#13;