滚动条在我的html5表格中添加了一个巨大的间隙



我正在用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;
}

间隙是因为标题行被视为另一个固定高度为100像素的tbody元素。

将其包裹在thead中,间隙将不再存在。

<table id="mytable">
    <thead>
        <tr>
            <th><span>Playlist</span></th>
        </tr>
    </thead>
    <tbody>
        ...

相关内容

最新更新