Inside Technique : Creating Scrollable Tables
This article explores creating a scrollable table for Internet Explorer 4.0 without requiring script. You can only create this scrollable table in Internet Explorer 4.0. For non-IE4 users, a traditional static table is displayed.
Internet Exploror 4.0 supports the CSS overflow property for creating scrollable regions in your document. This property is currently only supported on DIV and SPAN elements that have a width or height defined and cannot be used within a table for forcing a table to scroll. Therefore, creating a scrollable table is more an art that requires careful manipulation of HTML and CSS.
The contents in the table below are scrollable if you are using Internet Explorer 4.0, The header row stays static above the scrollbars. If you were to view the source for this page, you will notice this table is actually composed of two tables - one for the header row and a second for the actual contents:
To line up the tables, we defined a width on each column using the HTML 4.0 <COL> element. In addition,
since only Internet Explorer 4.0 currently provides support for the HTML 4.0 table enhancements, we defined the same width on the columns in the first row of the table.
This duplicate definition is only an attempt for browsers other than Internet Explorer 4.0 to line up the header with the contents. Below shows how
we defined the header for the table:
The table that makes up the contents are surrounded by a DIV element. This DIV element has a fixed width
that is 25 pixels greater than the width of the table. The extra pixels are to make room for the scrollbar.
To clean-up the appearance, we added a border to the bottom and left side of the DIV. The DIV and
the first row of the table are defined as follows:
While this approach appears simple enough, there are a number of caveats you need to look out for. When defining the table with the contents, the widths must be made the same as the widths used in the header. If any of the widths are set smaller than the width of a word in any cell, the tables will not line up. If this occurs, increase the width of the cell. Since the scrollbar width may vary on different machines, the extra space set aside for the scrollbars may not be enough. If you notice that the scrollbar is taking up space from the table, the width of the DIV needs to be increased.
This article explores one approach that we have been successful with. If you have an alternative approach, please tell us about it in our discussion forums.
© 1997-2000 InsideDHTML.com, LLC. All rights reserved.