user977154
user977154

Reputation: 1095

Scroll bar added a giant gap in my html5 table?

I am making a table in HTML5 and CSS. When I try to add a scroll bar, a giant gap appears in my table between the header and the body. Here is my code:

http://jsfiddle.net/AaronJohnson/u23g9/

HTML5 Code:

<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 Code:

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;
}

Upvotes: 0

Views: 223

Answers (1)

jeffjenx
jeffjenx

Reputation: 17487

The gap is because the header row is being treated as another tbody element, which has a fixed height of 100 pixels.

Wrap it in a thead and the gap will no longer be present.

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

Upvotes: 1

Related Questions