to limit the space:
<div style="width:800px; height:640px; overflow:auto">
<table .....
</table>
</div>
Main Topics
Browse All TopicsHi,
I am asking here a age old problem to make the HTML Table scrollable. Sure, in simple scenarios like having defined column width and the cell content fits the column width, one can handle this with two table concept. But in my case, i have no control over the column content, it may fit and it may not. The table has more than 30 columns and the data body may contain over 100 rows.
My requirement is to make the table scrollable (both horizontal and vertical) and sure, it needs to be cross-browser compatible.
Can someone please advice and provide some sample code?
I am asking this question in javascript forum because i don't think it can plainly be done with css.
Here you will find the example big table (only in columns, rows can be added more)!!
http://www.geocities.com/v
I have gone thru some links like
http://www.imaputz.com/css
Which doesn't work at all under IE7.
Thanks for your help.
fargo
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks mplungjan for your reply.
But how one can make the header fix? Doing the above it can only make the complete table scroll. I have updated the link
http://www.geocities.com/v
Sorry, I missed the fixed header
Here are millions: http://www.google.com/sear
If I look here
<table width="2000" border="1">
<colgroup>
<col width="45"/>
<col width="45"/>
<col width="45"/>
<col width="60"/>
<col width="160"/>
<col width="45"/>
<col width="350"/>
<col width="40"/>
<col width="45"/>
<col width="25"/>
<col width="100"/>
<col width="45"/>
<col width="180"/>
<col width="200"/>
<col width="45"/>
<col width="45"/>
<col width="25"/>
<col width="25"/>
<col width="25"/>
<col width="60"/>
</colgroup>
you already fix the width.
If I read your comments, this will not be the case in the real application?
In my comments, i mean to say that the width is surely fixed for the column. But what if the content on the data body for the cell goes beyond the specified width. A classic example is, if one has a dropdown box in the cell and the content of the dropdown box goes beyond the width of the column, then the HTML Table tries to adjust the width from other columns. isn't it?
To clearly visualise it, i have updated the link with the select box in the first cell. Even though the width for the column is set to 45, the content of the select box can make it bigger. This is exactly what i meant in my question. I hope the things are clear now. Thanks for your help.
You now have fixed sized columns - if you keep them fixed, e.g. make sure the content does not widen them, then you can take any of the fixed header scrollable table solutions out there without change.
If you do NOT want to have fixed size columns, then I need to know since I could possibly take an existing scrollable thing and programatically set the width of the header cells to the widest of the corresponding data cell in that column.
Michel
So the idea was great.
Too bad it does not work :((((
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script>
function resizeTable() {
var t1 = document.getElementById('h
var widths = new Array();
var cg = document.getElementById('c
for (var i=0,n=cg.childNodes.length
if (cg.childNodes[i].nodeType
continue;
}
widths[widths.length]=cg.c
}
var t2 = document.getElementById('d
var w,oldW;
for (var i=0, n=t2.rows.length; i<n;i++) {
for (var j=0, m=t2.rows[i].cells.length;
w = t2.rows[i].cells[j].offset
if (w>widths[j]) {
widths[j] = w;
oldW = t1.rows[0].cells[j].offset
t1.rows[0].cells[j].title=
t1.rows[0].cells[j].style.
t2.rows[i].cells[j].title=
t2.rows[i].cells[j].style.
t1.rows[0].cells[j].width=
}
}
}
}
//document.getElementById(
</script>
</head>
<body onLoad="resizeTable()">
<table width="2000" border="1" id="headers">
<colgroup id="cg">
<col width="45"/>
<col width="45"/>
<col width="45"/>
<col width="60"/>
<col width="160"/>
<col width="45"/>
<col width="350"/>
<col width="40"/>
<col width="45"/>
<col width="25"/>
<col width="100"/>
<col width="45"/>
<col width="180"/>
<col width="200"/>
<col width="45"/>
<col width="45"/>
<col width="25"/>
<col width="25"/>
<col width="25"/>
<col width="60"/>
</colgroup>
<tbody>
<tr>
<td class="header" align="center">Col-1</td>
<td class="header" align="center">Col-2</td>
<td class="header" align="center">Col-3</td>
<td class="header" align="center">Col-4</td>
<td class="header" align="center">Col-5</td>
<td class="header" align="center">Col-6</td>
<td class="header" align="center">Col-7</td>
<td class="header" align="center">Col-8</td>
<td class="header" align="center">Col-9</td>
<td class="header" align="center">Col-10</td>
<td class="header" align="center">Col-11</td>
<td class="header" align="center">Col-12</td>
<td class="header" align="center">Col-13</td>
<td class="header" align="center">Col-14</td>
<td class="header" align="center">Col-15</td>
<td class="header" align="center">Col-16</td>
<td class="header" align="center">Col-17</td>
<td class="header" align="center">Col-18</td>
<td class="header" align="center">Col-19</td>
<td class="header" align="center">Col-20</td>
</tr>
</table>
<div style="width:2000px; height:100px;overflow:auto
<table width="2000" border="1" id="data">
<colgroup>
<col width="45"/>
<col width="45"/>
<col width="45"/>
<col width="60"/>
<col width="160"/>
<col width="45"/>
<col width="350"/>
<col width="40"/>
<col width="45"/>
<col width="25"/>
<col width="100"/>
<col width="45"/>
<col width="180"/>
<col width="200"/>
<col width="45"/>
<col width="45"/>
<col width="25"/>
<col width="25"/>
<col width="25"/>
<col width="60"/>
</colgroup>
<tbody>
<tr id="tr0">
<td>
<select>
<option>Something very big can come here</option>
<option>One cannot control the width here</option>
</select>
</td>
<td>Value-2</td>
<td>Value-3</td>
<td>Value-4</td>
<td><input class="input" type="text" size="10" value="Value-5"/></td>
<td>Value-6</td>
<td>Value-7</td>
<td>Value-8</td>
<td>Value-9</td>
<td><input class="input" type="text" size="10" value="Value-10"/></td>
<td>Value-11</td>
<td>Value-12</td>
<td>Value-13</td>
<td>Value-14</td>
<td><input class="input" type="text" size="10" value="Value-15"/></td>
<td>Value-16</td>
<td>Value-17</td>
<td>Value-18</td>
<td>Value-19</td>
<td>Value-20</td>
</tr>
<tr id="tr1">
<td>Value-1</td>
<td>Value-2</td>
<td>Value-3</td>
<td>Value-4</td>
<td><input class="input" type="text" size="10" value="Value-5"/></td>
<td>Value-6</td>
<td>Value-7</td>
<td>Value-8</td>
<td>Value-9</td>
<td><input class="input" type="text" size="10" value="Value-10"/></td>
<td>Value-11</td>
<td>Value-12</td>
<td>Value-13</td>
<td>Value-14</td>
<td><input class="input" type="text" size="10" value="Value-15"/></td>
<td>Value-16</td>
<td>Value-17</td>
<td>Value-18</td>
<td>Value-19</td>
<td>Value-20</td>
</tr>
<tr id="tr3">
<td>Value-1</td>
<td>Value-2</td>
<td>Value-3</td>
<td>Value-4</td>
<td><input class="input" type="text" size="10" value="Value-5"/></td>
<td>Value-6</td>
<td>Value-7</td>
<td>Value-8</td>
<td>Value-9</td>
<td><input class="input" type="text" size="10" value="Value-10"/></td>
<td>Value-11</td>
<td>Value-12</td>
<td>Value-13</td>
<td>Value-14</td>
<td><input class="input" type="text" size="10" value="Value-15"/></td>
<td>Value-16</td>
<td>Value-17</td>
<td>Value-18</td>
<td>Value-19</td>
<td>Value-20</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Business Accounts
Answer for Membership
by: mplungjanPosted on 2007-09-03 at 02:50:22ID: 19819858
<table style="overflow:auto">
or
<div style="overflow:auto">
<table .....
</table>
</div>