cjmackenzie
asked on
How to scroll the body of a table, leaving the headings visible
I want my table to sit in the bottom 75% of my web page, and when there is too much data to see in that space, I want to scroll the table. Currently the table is populated on a separate page and dispalyed in an inline frame. Problem is, when the user scrolls, the headings disappear from view.
I thought i might be able to style the body of the table as follows:
.mytableclass tbody{
height:500px;
overflow:scroll;
}
But this appears to set the height of the tables rows, not the height of the body.
I am using IE6 in an intranet, so I only have to worry about that browser.
Any ideas?
I thought i might be able to style the body of the table as follows:
.mytableclass tbody{
height:500px;
overflow:scroll;
}
But this appears to set the height of the tables rows, not the height of the body.
I am using IE6 in an intranet, so I only have to worry about that browser.
Any ideas?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
IE only!
Cd&
Cd&
Yes. IE only.
> I am using IE6 in an intranet, so I only have to worry about that browser.
> I am using IE6 in an intranet, so I only have to worry about that browser.
True, but they started out trying to use th estandard compliant method, so I gave them cross-browser. For IE only, there is no way I would go to an htc when there is s a sommple scripted solution that handles variable width columns and re-sizing:
Cd&
<html>
<head>
<style>
table#headers, table#data {table-layout:fixed;backgr ound:#dda0 dd;}
td, th {vertical-align:top;backgr ound:#ffff ff;}
</style>
<script language="javascript">
function init() {
var eTable = document.getElementById("h eaders");
eTable.style.width=documen t.getEleme ntById('da ta').offse tWidth+'px ';
document.getElementById('t h1').style .width=doc ument.getE lementById ('td1').of fsetWidth+ 'px';
document.getElementById('t h2').style .width=doc ument.getE lementById ('td2').of fsetWidth+ 'px';
document.getElementById('t h3').style .width=doc ument.getE lementById ('td3').of fsetWidth+ 'px';
document.getElementById('t h4').style .width=doc ument.getE lementById ('td4').of fsetWidth+ 'px';
}
window.onload = init;
window.onresize=init;
</script>
<style>
table#headers, table#data {background:#dda0dd;}
td, th {vertical-align:top;backgr ound:#ffff ff;}
</style>
</head>
<body>
<table cellpadding="4" cellspacing="1" id="headers">
<tr>
<th id="th1">T</th>
<th id="th2">H</th>
<th id="th3">Y</th>
<th id="th4">H</th>
</tr>
</table>
<div style="width:100%;height:3 00px;overf low:auto;" >
<table cellpadding="4" cellspacing="1" width="100%" id="data">
<tr>
<td id="td1">Data</td>
<td id="td2">Hello</td>
<td id="td3" style="width:60%">I am here and so are you</td>
<td id="td4">Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I..................... .......... .......... ..xxxxxxxx xxxxxxxxxx xxxx</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
</table>
</div>
</body>
</html>
Cd&
<html>
<head>
<style>
table#headers, table#data {table-layout:fixed;backgr
td, th {vertical-align:top;backgr
</style>
<script language="javascript">
function init() {
var eTable = document.getElementById("h
eTable.style.width=documen
document.getElementById('t
document.getElementById('t
document.getElementById('t
document.getElementById('t
}
window.onload = init;
window.onresize=init;
</script>
<style>
table#headers, table#data {background:#dda0dd;}
td, th {vertical-align:top;backgr
</style>
</head>
<body>
<table cellpadding="4" cellspacing="1" id="headers">
<tr>
<th id="th1">T</th>
<th id="th2">H</th>
<th id="th3">Y</th>
<th id="th4">H</th>
</tr>
</table>
<div style="width:100%;height:3
<table cellpadding="4" cellspacing="1" width="100%" id="data">
<tr>
<td id="td1">Data</td>
<td id="td2">Hello</td>
<td id="td3" style="width:60%">I am here and so are you</td>
<td id="td4">Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I.....................
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
<tr>
<td>Data</td>
<td>Hello</td>
<td>I am here and so are you</td>
<td>Yoohoo</td>
</tr>
</table>
</div>
</body>
</html>
Hey CobolDinosaur - isnt that exactly what I suggested????
Using two tables?
What is the javascript for - He has no problem with table widths?????
The problem is that he wants to scroll without losing the titles
Using two tables?
What is the javascript for - He has no problem with table widths?????
The problem is that he wants to scroll without losing the titles
With seperate tables the widths may not stay in synch with chages in content or screen size.
Cd&
Cd&
If you use two different tables for headers and content, the headers don't line up with the content. His script fixes that.
Awww ok - I just assumed 100% width with equal spaced table widths :)
Good point tho - sorry im not thinkin on all levels today :D
Good point tho - sorry im not thinkin on all levels today :D
ASKER
Fantastic! I really like the answers I got here.
I thought I needed to split the table, or use divs instead, but while I had fixed the width of my table, I hadn't fixed the width of all my columns. So neester's answer was what I thought I'd have to do. CobolDinosaurs code builds on that and means I don't have to fix widths of columns and who knows - maybe at some point in the future I'll need cross browser so it's great to have that at my fingertips.
Thanks also to ftaco96. I don't know what an htc is, although I've a better idea now. Now if I want I can add an htc to my project, then any existing tables where I want to scroll the body, just add one line to the css and a couple of tags to the table.
I'm going to increase the point for this so I can share them around.
Many thanks to all of you.
Colin
I thought I needed to split the table, or use divs instead, but while I had fixed the width of my table, I hadn't fixed the width of all my columns. So neester's answer was what I thought I'd have to do. CobolDinosaurs code builds on that and means I don't have to fix widths of columns and who knows - maybe at some point in the future I'll need cross browser so it's great to have that at my fingertips.
Thanks also to ftaco96. I don't know what an htc is, although I've a better idea now. Now if I want I can add an htc to my project, then any existing tables where I want to scroll the body, just add one line to the css and a couple of tags to the table.
I'm going to increase the point for this so I can share them around.
Many thanks to all of you.
Colin
Glad we could help. Thanks for the A. :^)
Cd&
Cd&
I disagree about the headaches though ;)
Martin