我想修復我的表頭。我從StackOverflow's Answer之一找到了答案,但是,我在使用該代碼時遇到了問題。我想要用百分比指定標題大小,以便當用戶放大/縮小頁面時,表格會調整它自己。固定表頭不佔用全屏
在此代碼中,當標題大小與表數據行不匹配時。如果我在CSS
中註釋掉position
標記,那麼標題將自己與表數據行對齊,但它使它成爲非固定標題。有些人可以幫助獲取標題與表格數據行對齊並佔據整個屏幕(以不同標題指定的大小,並且相應的數據行可以有不同的寬度)。
<style type="text/css">
table
{
width:100%;
border:1px solid #000000;
}
thead
{
background-color:#000268;
color:#FFFFFF;
text-align:center;
position:fixed;
top:0px;
width:100%;
}
thead th
{
text-align:center;
border-width: 1px;
border-style: outset;
}
thead.th.hd1
{
width:20%
text-align:center;
border-width: 1px;
border-style: outset;
}
tbody {
color:#000000;
text-align:center;
height:150px;
overflow: scroll;
margin:0px;
width:100%;
}
tbody td
{
height:60px;
width:100px;
border-width: 1px;
border-style: outset;
}
</style>
<table>
<thead>
<tr><th class = "hd1">Head1</th><th class = "hd1">Head2</th><th class = "hd1">Head3</th><th class = "hd1">Head4</th><th class = "hd1">Head5</th><th class = "hd1">Head6</th></tr>
</thead>
<tbody>
<tr><td>r1c1</td><td>r1c2</td><td>r1c3</td><td>r1c4</td><td>r1c5</td><td>r1c6</td></tr>
<tr><td>r2c1</td><td>r2c2</td><td>r2c3</td><td>r2c4</td><td>r2c5</td><td>r2c6</td></tr>
<tr><td>r3c1</td><td>r3c2</td><td>r3c3</td><td>r3c4</td><td>r3c5</td><td>r3c6</td></tr>
<tr><td>r4c1</td><td>r4c2</td><td>r4c3</td><td>r4c4</td><td>r4c5</td><td>r4c6</td></tr>
<tr><td>r5c1</td><td>r5c2</td><td>r5c3</td><td>r5c4</td><td>r5c5</td><td>r5c6</td></tr>
<tr><td>r6c1</td><td>r6c2</td><td>r6c3</td><td>r6c4</td><td>r6c5</td><td>r6c6</td></tr>
<tr><td>r7c1</td><td>r7c2</td><td>r7c3</td><td>r7c4</td><td>r7c5</td><td>r7c6</td></tr>
<tr><td>r8c1</td><td>r8c2</td><td>r8c3</td><td>r8c4</td><td>r8c5</td><td>r8c6</td></tr>
<tr><td>r9c1</td><td>r9c2</td><td>r9c3</td><td>r9c4</td><td>r9c5</td><td>r9c6</td></tr>
<tr><td>r10c1</td><td>r10c2</td><td>r10c3</td><td>r10c4</td><td>r10c5</td><td>r10c6</td></tr>
<tr><td>r11c1</td><td>r11c2</td><td>r11c3</td><td>r11c4</td><td>r11c5</td><td>r11c6</td></tr>
<tr><td>r12c1</td><td>r12c2</td><td>r12c3</td><td>r12c4</td><td>r12c5</td><td>r12c6</td></tr>
<tr><td>r13c1</td><td>r13c2</td><td>r13c3</td><td>r13c4</td><td>r13c5</td><td>r13c6</td></tr>
<tr><td>r14c1</td><td>r14c2</td><td>r14c3</td><td>r14c4</td><td>r14c5</td><td>r14c6</td></tr>
<tr><td>r15c1</td><td>r15c2</td><td>r15c3</td><td>r15c4</td><td>r15c5</td><td>r15c6</td></tr>
</tbody>
</table>
儘量把你的代碼中的jsfiddle – Abhimanyu
這麼多細胞..我的眼睛 – George