【发布时间】:2016-03-08 18:14:11
【问题描述】:
我正在尝试构建一个具有两个独立内容组的布局:一个在左侧和一个右侧,目前具有固定宽度 (20%/80%)。在每一侧,我都尝试使用 flexbox 来排列内容:左侧面板使用flex-direction: column,右侧面板使用flex-direction: row wrap。每一面的内容数量可以是灵活的。内容较少的面板应与另一侧“更高”的高度相匹配。
到目前为止,我能够实现基本布局,如jsfiddle所示。但是,我的问题是我无法使“较短”面板填充高度,即使我将高度设置为 100%。在给定的示例中,左侧面板的“C”div 和右侧面板的“Box7”div 之间有一个空白区域。 html/css 代码如下所示。
我该如何解决这个问题,或者有更好更简单的布局解决方案吗?任何帮助将不胜感激。
HTML
<div class='top'>
<div class='left'>
<div class='litem'>A</div>
<div class='litem'>B</div>
<div class='litem'>C</div>
</div>
<div class='right'>
<div class='ritem'>Box 1</div>
<div class='ritem'>Box 2</div>
<div class='ritem'>Box 3</div>
<div class='ritem'>Box 4</div>
<div class='ritem'>Box 5</div>
<div class='ritem'>Box 6</div>
<div class='ritem'>Box 7</div>
</div>
</div>
CSS
* { outline: 1px solid Grey; }
html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background-color: Cornsilk;
}
.top {
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
width: 100%;
height: 100%;
}
.left {
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
width: 20%;
height: 100%;
}
.right {
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 80%;
height: 100%;
}
.litem, .ritem {
margin: 0;
padding: 0;
}
.litem { height: 50%; }
.ritem { height: 50%; width: 33.3%;}
.litem:nth-child(1) { background-color: Cyan; }
.litem:nth-child(2) { background-color: DarkCyan; }
.litem:nth-child(3) { background-color: DarkSeaGreen; }
【问题讨论】: