表与tbody内的垂直滚动条

时间:2016-10-26 14:25:35

标签: html css

如何在tbody中获得垂直滚动条?

HTML:

<table class="table table-striped table-bordered">
    <thead>
        <tr>
            <th>Header1</th>
            <th>Header2</th>
            <th>Header3</th>
            <th>Header4</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Cell1</td>
            <td>Cell2</td>
            <td>Cell3</td>
            <td>Cell4</td>
        </tr>
    </tbody>
</table>

表应响应并且宽度设置为100%

在我的代码中有13个标题:https://jsfiddle.net/r5Ly00mq/

1 个答案:

答案 0 :(得分:0)

thead, tbody { display: block; }

tbody {
    height: 100px;       /* Just for the demo          */
    overflow-y: auto;    /* Trigger vertical scroll    */
    overflow-x: hidden;  /* Hide the horizontal scroll */
}

链路: - HTML table with 100% width, with vertical scroll inside tbody