我在HTML5和CSS中创建一个表。当我尝试添加一个滚动条时,我的表格中会在标题和正文之间出现一个巨大的间隙。这是我的代码:
http://jsfiddle.net/AaronJohnson/u23g9/
HTML5代码:
<table id="mytable">
<tr>
<th> <span>
Playlist
</span>
</th>
</tr>
<tbody>
<tr>
<td> <span>
LINK 1
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 2
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 3
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 4
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 5
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 6
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 7
</span>
</td>
</tr>
</tbody>
</table>
CSS代码:
table#mytable {
width:100%;
border-collapse:separate;
background:crimson;
border-radius: 15px;
}
tbody {
overflow: auto;
height: 100px;
float: left;
width: 100%;
}
td {
text-align:center;
background:gray;
border-bottom:5px solid black;
border-radius: 15px;
}
th {
font-weight:bold;
text-align:center;
background:crimson;
border-bottom:5px solid black;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
float: left;
width: 100%;
}
tr {
width: 100%;
display: table;
}
答案 0 :(得分:1)
差距是因为标题行被视为另一个tbody
元素,其固定高度为100像素。
将其包裹在thead
中,差距将不再存在。
<table id="mytable">
<thead>
<tr>
<th><span>Playlist</span></th>
</tr>
</thead>
<tbody>
...