在滚动期间,表头需要保持固定

cdu*_*dub 4 html css jquery html-table css-position

我有一个带有标题和正文的表格,我希望表格标题在主体上滚动时保持固定.

该表设置如下:

<table>
    <thead>
        <tr>
            <th>Header 1</th>
            <th>Header 2</th>
            <th>Header 3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Data 1</td>
            <td>Data 2</td>
            <td>Data 3</td>
        </tr>

        ...more rows for data...

    </tbody>
Run Code Online (Sandbox Code Playgroud)

该表用一个封装,并具有CSS,如:

overflow-x: hidden;
overflow-y: auto;
height: 400px;
Run Code Online (Sandbox Code Playgroud)

我需要表头保持完全静止,但当我添加position:fixed; 对于thead或个人而言,标题会被压扁.

这是最好的方法吗?

mko*_*yak 18

我刚刚更新了一个我写的插件,它确实做了这件事:

http://mkoryak.github.io/floatThead/

它可能是你需要的