开发者

Keeping a certain row or column in an HTML table fixed

I have huge amounts of data populating an HTML <table> having more than 200 rows and 200 columns.

However, when I scroll the page horizontally or vertically to view the data, the header columns (like th for instance) go beyond the page.

How can I scroll开发者_JAVA百科 through the table and still keep the top row and leftmost column fixed so that I will always know what data I'm seeing.


Here is a good solution: http://www.imaputz.com/cssStuff/bigFourVersion.html

Although implementing a JavaScript/jQuery solutions opens a lot more doors.

See this SO post for more info: HTML table with fixed headers?


You can use jQuery or you can try to mix the solution below:

header: http://fixed-header-using-jquery.blogspot.com/2009/05/scrollable-table-with-fixed-header-and.html

header and first column too but still in beta: http://fixedheadertable.mmalek.com

Just the first column fixed: http://www.java2s.com/Code/HTMLCSS/Table-Style/Fixedtablefirstcolumn.htm


Use simple solutions when they exist. :)
You can use a tbody and give it either fixed height or max-height and overflow: auto;:

CSS:

tbody {
  max-height: 500px;
  max-width: 100%;
  overflow: auto;
}

And HTML like so:

<table>
<thead>
<tr><th>headers</th></tr>
</thead>
<tbody>
<tr><td>body</td></tr>
</tbody>
<tfoot>
<tr><td>footers</td></tr>
</tfoot>
</table>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜