How can I let a table's body scroll but keep its head fixed in place?

minty picture minty · Sep 25, 2008 · Viewed 226.9k times · Source

I am writing a page where I need an HTML table to maintain a set size. I need the headers at the top of the table to stay there at all times but I also need the body of the table to scroll no matter how many rows are added to the table. Think a mini version of excel. This seems like a simple task but almost every solution I have found on the web has some drawback. How can I solve this?

Answer

Ken Penn picture Ken Penn · Sep 29, 2008

I had to find the same answer. The best example I found is http://www.cssplay.co.uk/menu/tablescroll.html - I found example #2 worked well for me. You will have to set the height of the inner table with Java Script, the rest is CSS.