4

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.

2
  • Please post example HTML to help people work on this. Commented Aug 18, 2010 at 21:11
  • 1
    I 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)? Commented Aug 19, 2010 at 3:23

4 Answers 4

2

This solution might work for you depending on the style of your headers. It's pure CSS. http://salzerdesign.com/blog/?p=191

Sign up to request clarification or add additional context in comments.

Comments

1

Why would you not just use a and set a height and width for it allowing overflow. Then just simply place your table in there and you are good to go.

To me that just seems like the most logic and easiest way to go about it...

Comments

0

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());
});

jsFliddle demo

Comments

0

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

2 Comments

I didn't use any window resizing observers ;-)
HTTP 404. This is why it's always best to include code in answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.