I realize this question has been asked quite a bit on Stack Overflow; however, after looking through a number of them, I believe my question has one more requirement. I want to transform a regular html table, into a table that can be scrolled both vertically and horizontally, while the the header remains at the top. The width of this table exceeds the width of the page, so I need the headers to move horizontally as the table is scrolled. I would prefer to use a pure CSS method; however, I will use Javascript if necessary. Have yet to find a solution that does all of this.
-
Please post example HTML to help people work on this.donohoe– donohoe2010-08-18 21:11:07 +00:00Commented Aug 18, 2010 at 21:11
-
1I can understand wanting your header to "stick" while scrolling vertically, but why horizontally? Wouldn't that defeat the purpose of a table header (each of which labels the column beneath it)?peterjmag– peterjmag2010-08-19 03:23:14 +00:00Commented Aug 19, 2010 at 3:23
4 Answers
This solution might work for you depending on the style of your headers. It's pure CSS. http://salzerdesign.com/blog/?p=191
Comments
well you can use JQuery to do this in few lines of code, you can see my other post to create a table with fix header and scrollable body
Create Table with scrollable body
after that lets imagine you have one div for the headers with class name = "Top1" and one div for the body with class name = "Top2", you can bind the scroll of one to the other
$('.Top2').bind('scroll', function(){
$(".Top1").scrollLeft($(this).scrollLeft());
});
$('.Top1').bind('scroll', function(){
$(".Top2").scrollLeft($(this).scrollLeft());
});
Comments
Here is a good jQuery plugin, working in all browsers! (check out the demo)
The result is a table with a fixed header, scrolling (for the moment..) only vertically, but with a variable width.
I develop this plugin to meet the problem of fixed header + flexible width.
Check it: https://github.com/benjaminleouzon/tablefixedheader