table中设置thead固定,tbody 垂直滚动条

html:

<div class="fixed-table">
    <div class="fixed-table-header"></div>
    <div class="fixed-table-content">
        <table class="table table-hover table-striped">
            <thead>
            <tr>
                <th><div class="th-inner">a</div></th>
                <th><div class="th-inner">s</div></th>
                <th><div class="th-inner">d</div></th>
                <th><div class="th-inner">f</div></th>
                <th><div class="th-inner">g</div></th>
                <th><div class="th-inner">h</div></th>
                <th><div class="th-inner">j</div></th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>asdf</td>
                <td>asdf</td>
                <td>asdf</td>
                <td>asdf</td>
                <td>asdf</td>
                <td>asdf</td>
                <td>asdf</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

css:

/* table scroll */
.fixed-table {
    position: relative;
    margin-bottom: 10px;
}
.fixed-table-header {
    position: absolute;
    top: 0;
    width: 100%;
    height: 33px;
    background-color: #eee;
    border-bottom: 1px solid #ddd;
}
.fixed-table-content {
    height: 200px;
    overflow-y: auto;
}
.fixed-table-content table .th-inner {
    position: absolute;
    top: 0;
    height: 33px;
    line-height: 33px;
}
.th-inner:not(:first-child) {
    border-left: 1px solid #ddd;
}
.fixed-table-content .table>tbody>tr>td {
    padding-left: 8px;
}

 

posted @ 2018-01-27 15:49  miny_simp  阅读(1110)  评论(0编辑  收藏  举报