【发布时间】:2019-03-14 19:36:26
【问题描述】:
我正在尝试创建一个顶部、中间和底部的模式。顶部始终是固定高度。
底部必须“粘合”到底部,并且可能会有所不同。它里面的所有内容和元素都必须从底部构建。因此,如果有一行文本,底部将是该行的高度。如果有 3 或 4 行文字,底部会根据需要向上推。
中间需要填满所有剩下的,并且如果内容overflow-y的它必须显示滚动条并且不干扰顶行或底行。
我该怎么做?我在尝试overflow-y: auto 时发现它不起作用,大概是因为没有高度,而是将桌子推到了#wrap div 的范围之外。
这是一个 CodePen:https://codepen.io/sfullman/pen/XGZoJb
body{
font-family: Arial;
}
.table{
display: table;
height: 100%;
width: 100%;
}
.row{
display: table-row;
}
.cell{
display: table-cell;
width: 75%;
}
#top{
background-color: burlywood;
height: 41px;
}
#middle .cell{
overflow-y: scroll;
}
#bottom{
height: 15px; /* make this height less than expected height, table row/cell behavior will successfully exceed it an push content up */
border-top: 1px solid darkred;
background-color: rgba(0,0,0,.15);
}
#wrap{
/* this div is designed to be a dialog/modal and will normally be abs. positioned */
border: 1px solid darkred;
width: 425px;
height: 300px;
position: absolute;
top: 20px;
left: 20px;
}
<div id="wrap">
<div id="innerTable" class="table">
<div id="top" class="row">
<div class="cell">
top
</div>
</div>
<div id="middle" class="row">
<div class="cell">
middle<br>
middle<br>
middle<br>
middle<br>
middle<br>
middle<br>
middle<br>
middle<br>
middle<br>
middle<br>
middle<br>
middle<br>
</div>
</div>
<div id="bottom" class="row">
<div class="cell">
bottom<br>
bottom<br>
bottom<br>
</div>
</div>
</div>
</div>
【问题讨论】:
标签: html css css-tables