Attached Img.
請參閱附加圖片。我有一個Header
,content
和Footer
。css - 在剩餘高度(頁眉和頁腳之間)放置可滾動表格
Header
和Footer
都是固定的。它們應始終可見。
而在content
裏面,我有一個<table>
。我想讓這<table>
採取header
和footer
之間的所有剩餘高度。
該表可能包含大量數據,所以我想讓它也可以滾動。
下面的片段展示了我通過將table
到最接近的一個div
與overflow-y: auto; max-height: 200px;
(固定大小)
我怎樣才能讓它自動取足/剩餘高度?
body {
background: green;
padding: 10px;
}
.header {
background: lightblue;
}
.content {
background: lime;
overflow-y: auto;
max-height: 200px;
}
.footer {
background: orange;
}
<div class="header">
Some awesome title
</div>
<div class="content">
<table>
<thead>
<tr>
<th>Lorem.</th>
<th>Numquam.</th>
<th>Id.</th>
</tr>
</thead>
<tbody>
<tr>
<td>Lorem.</td>
<td>Eos.</td>
<td>Vel.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Quod.</td>
<td>Quaerat?</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Explicabo!</td>
<td>Esse.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Quo.</td>
<td>Praesentium!</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Perferendis!</td>
<td>Necessitatibus.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Facere.</td>
<td>Ex.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Ducimus.</td>
<td>Architecto.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Porro!</td>
<td>Voluptatum.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Culpa?</td>
<td>Dignissimos?</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Alias.</td>
<td>Deserunt!</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Mollitia!</td>
<td>Doloribus?</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Quia.</td>
<td>Aspernatur.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Est!</td>
<td>Nihil.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Neque.</td>
<td>Asperiores!</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Cupiditate.</td>
<td>Rerum.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Eligendi.</td>
<td>Qui?</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Libero.</td>
<td>Molestiae!</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Suscipit.</td>
<td>Nostrum.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Minima.</td>
<td>Voluptatem.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Quam.</td>
<td>Mollitia.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Minus!</td>
<td>Corporis.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Perferendis.</td>
<td>Deleniti.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Asperiores!</td>
<td>Rem.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Molestiae.</td>
<td>Dignissimos?</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Doloribus.</td>
<td>Ipsam.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Aperiam.</td>
<td>Obcaecati.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Suscipit.</td>
<td>Harum?</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Cupiditate.</td>
<td>Tenetur.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Ea!</td>
<td>Ipsam.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Officia!</td>
<td>Velit.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Mollitia!</td>
<td>Voluptatibus.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Rerum.</td>
<td>Accusamus?</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Distinctio.</td>
<td>Ducimus.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Iure.</td>
<td>Recusandae.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Quibusdam.</td>
<td>Veritatis.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Optio!</td>
<td>Voluptatum.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>At.</td>
<td>Facere.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Illum?</td>
<td>Placeat!</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Unde?</td>
<td>Explicabo.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Reiciendis.</td>
<td>Architecto.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Quasi?</td>
<td>Praesentium!</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Odit!</td>
<td>Ratione.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Expedita?</td>
<td>Incidunt!</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Nemo.</td>
<td>Reprehenderit?</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Blanditiis.</td>
<td>A.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Iusto.</td>
<td>Similique.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Sint?</td>
<td>Corrupti.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Consequatur.</td>
<td>Nihil!</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Magni.</td>
<td>Deleniti.</td>
</tr>
<tr>
<td>Lorem.</td>
<td>Nobis!</td>
<td>Eius.</td>
</tr>
</tbody>
</table>
</div>
<div class="footer">
Pagination stuff
</div>
謝謝,我可以看到爲什麼後者會是首選。對於我在問題中提到的情況,我肯定會這樣做。 由於我沒有提供,也預測我會添加額外的控件(如子標題/子頁腳,例如:選擇項目>編輯控件'''刪除'),flexbox運行良好對於這樣的場景。 – user7552