背景: 我使用CSS創建一個Web應用程序的體驗,在網頁上的一切總是可見的,只是在某些panes
是滾動的。我現在需要將其擴展到表格。我希望表頭始終保持可見(有時是頁腳),但表格主體只能滾動。粘表頭與100%的高度「窗格」
我到目前爲止所做的工作是對thead
和tfoot
應用「窗格」類,然後使tbody
自動填充高度,然後使其滾動。所有這些工作除了thead,tbody和tfoot不再是100%寬度。這種方法似乎讓我離我想要的最近。
小提琴: 我有一個的jsfiddle這讓我接近,這也顯示出我使用創建的固定和滾動panes
代碼。 http://jsfiddle.net/va4HF/1/
要求:理想我想保持我的pane
CSS,因爲它是,但與之相適應需要一個表時。我也想只保留這個CSS。
以下代碼是我的概念證明代碼,並且還包含面板CSS。
HTML:
<div class="column">
<div class="pane top">Top</div>
<div class="pane middle">
<table>
<thead class="pane table-head">
<tr>
<th>Header</th>
</tr>
</thead>
<tbody class="pane table-body fill">
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
<tr><td>Text</td></tr>
</tbody>
<tfoot class="pane table-foot">
<tr>
<th>Footer</th>
</tr>
</tfoot>
</table>
</div>
<div class="pane bottom">Bottom</div>
</div>
CSS:
body, html {
height:100%;
margin:0;
padding:0;
}
div {
box-sizing:border-box;
box-sizing:content-box\9; /* Fix for IE9 sizing */
-moz-box-sizing:border-box; /* Fix for firefox sizing */
}
.column {
position:absolute;
width:100%;
min-height:100%;
height:auto;
overflow:hidden;
}
.pane {
position:absolute;
width:100%;
overflow:hidden;
}
.fill {
height:auto;
overflow:auto;
}
.top {
background:pink;
height: 20%;
top:0;
}
.middle {
background:red;
top:20%;
bottom:50px;
}
.table-head {
height: 40px;
top:0;
}
.table-body {
top:40px;
bottom:40px;
}
.table-foot {
height: 40px;
bottom:0;
}
.bottom {
background:orange;
height: 50px;
bottom:0;
}
table thead tr, table tfoot tr {background:rgba(0,0,0,0.5);}
table tbody tr {background:rgba(0,0,0,0.3);}
table td, table th {padding:10px; color:#fff;}
/* Fix for Safari scrollbars (also styles Chrome scrollbars) */
.fill::-webkit-scrollbar {-webkit-appearance: none;width: 10px;}
.fill::-webkit-scrollbar-track {background-color: rgba(0,0,0, .3);border-radius: 0px;}
.fill::-webkit-scrollbar-thumb {border-radius: 0px; background-color: rgba(255,255,255, .4);}
研究: 別人已經在Table that Fills 100% Parent Height with Fixed Header/Footer問到這個類似的情況,但一直沒有得到很好的響應,並結束隨着Javascript,但我想嘗試找到一個CSS解決方案。或者至少是一個簡單的JavaScript解決方案,他用那什麼(避免疊加三個表)
謝謝。它符合我的需求 – smenon