I am attempting to create a page with tabular data, which must appear as multiple tables. I have two conflicting requirements to get around, however:
- Each table must have a border around it.
- Column widths for each table must be able to re-size based upon the content. However, the column widths must be consistent across all tables. (i.e. the size of a column is based upon the largest cell in that column across all tables).
To handle the second requirement, I have a single, top-level table which contains multiple thead and tbody sections. This accomplishes #2 beautifully. Essentially, I have created multiple pseudo-tables within a larger parent table, grouped as a single thead with an accompanying tbody:
<table>
<thead>
table1 header content...
</thead>
<tbody>
table1 body content...
</tbody>
<thead>
table2 header content...
</thead>
<tbody>
table2 body content...
</tbody>
</table>
Now, I am attempting to address the first requirement. Each pseudo table must have a border around it, passing itself off as a genuine table.
I have found, to my dismay, that IE 6/7 do not allow for adding border styles around thead/tbody tags, or I would simply have added a top/left/right border style to thead and a bottom/left/right border style to tbody.
Creating genuine tables and styling borders for those works to solve #1, but it breaks #2.
Another alternative would be to use first-child and last-child styles to create my borders. Unfortunately, this is neither pretty, nor does it work in IE 6/7.
Another alternative I have been looking into is creating a border around the entire table and attempting to create a row between the pseudo-tables which creates my separation, but while I can create top/bottom borders for it ok, I have yet to discover a means to erase the table's left/right border for just that row. Is that possible?
My last-ditch alternative is to create classes for drawing left, right, top, and bottom borders, setting the appropriate table cells to use these classes. I know this will ultimately work, but it is horribly clunky and makes for really messy markup. Colgroups cannot save me here, as they are incapable of handling border styles. That is unfortunate, as it would make this solution a little easier to stomach.
Is there a better method to accomplish the borders that I may have missed?