Freeze table headers pure CSS?

I have large, dynamically driven tables with columns of varying widths. I was hoping to find a pure CSS way to implement this but so far all I’ve found are solutions for tables with fixed column widths. Is there a way to freeze table headers when you have tables with variable width columns?

Here you go.

We had a quiz on this not too long ago.

Excellent quiz! Is there a solution that doesn’t require a fixed table height? What I’m hoping for is to allow the table to extend however far it needs to but to be able to scroll while keeping the header in place. I don’t really need a footer.

Then don’t put a footer in there. And you don’t want a height…but when do you want scrolling…?

Just regular page scrolling. There’s a js example here but was hoping to to it without js:

The problem is that I’m building an application for many users so the table lengths may vary widely. Some users may only have 2 or 3 rows in a table - others may have several hundred. I’m trying to find a fix that won’t affect the look of the page for users with only a few rows, but that will kick in the header freeze for longer tables. I’m open to other ideas.

In Opera it is glitchy a little bit. And no as far as I know there are no ways.

Ok, thanks. I may end up using the one above - just need to play with it a bit in my head.

Probably a dumb question but I assume there’s no way to add a min-height kind of thing so I could set the table at 6 or 7 rows for the default and then have it stretch for users with more data?

min-height wil still allow for expansion and thus you will have to set a max-height in conjunction with that to stop it at a certain point to allow the scrollbars to take effect.

You will need an expression for IE6 though.

Ok - well, that would take care of some of my reservations. What’s the IE6 fix for that?

What’s the IE6 fix for what?

You said that I’d need an expression for IE6 - wasn’t sure what you meant.

Yes you need an expression for max-height. View the FAQs at the top of this thread on how t odo that. Or just google “IE6 max-height expression”. There are many articles on this.