Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get THEAD/TFOOT/TBODY to work 1

Status
Not open for further replies.

msc0tt

IS-IT--Management
Jun 25, 2002
281
CA
Hello,
I'm experimenting with table headers/footers, and can't get it to work! My objective is to repeat the header and footer when the table spans multiple pages. Below is my sample that I'm playing with. When I go into print preview, it shows the header on the first page, and the footer on the last page. Hmph!

Note: I know I'm not closing my internal table element tags. I saw a reference that says this is valid, and it is so much cleaner to look at. (my problem exists even with all these closing tags present).
-with thanks


<HTML><HEAD>
<TITLE>My Title</TITLE>
</HEAD>

<BODY>
<table border="1" width="75%" rules="groups">
<thead><tr><th>Header line for table
<tfoot><tr><th>Footer line for table
<tbody>
<tr><td>This table is where the line items for the report would go
<tr><td>(obviously, the border lines would be hidden)<br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
<tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br> <tr><td><br>
</table>

</BODY></HTML>
 
Ok. First the solution. According to this article this can be solved with css by putting the following lines in your styles:

thead {display: table-header-group;}
tfoot {display: table-footer-group;}

The example on that page was working for me in IE6 and Mozilla but interestingly enough not on Opera. That still covers most of the users and doesn't cause any problems for others.

Regarding your coding -- while W3 states that in HTML 4.01 using closing tags for table elements is optional I strongly advise against it. In the upcoming W3 recommended standards -- XHTML all elements must be closed so it is best practice to get used to that sooner rather than later.
 
Thanks Vragabond. Almost all the examples I found DO NOT mention the css bit (don't they check their example code?!?). Sure enough, now it works as advertised.

As an aside, have you ever used the TFOOT to simulate a page footer? What can be done about the last page to get the footer to always print at the bottom of the physical page? (p.s. I can't just pad the bottom of the table to fit, since the table is of arbitrary length).
-Mike

p.s. Too bad about the XHTML thing requiring all closing tags, even when they're implied. (i.e. when a <TR> is encountered within a table, is it implied that the previous <TR> and <TH> have now been closed).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top