Forum Moderators: not2easy
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Some Title</title>
<style>
<!--
table {
border-collapse : collapse;
table-layout : fixed;
}
td, th {
background-color: #aaaaaa;
border-right : 1px solid #ffffff;
color : #ffffff;
width : 50px;
text-align : center;
}
td.locked_left, th.locked_left {
background-color: #88ff88;
font-weight : bold;
left: 0px;
border-left : 1px solid #ffffff;
position : relative;
z-index: 1;
}
#table_container {
width : 200px;
overflow : scroll;
}
-->
</style>
<script type="text/javascript">
if(document.getElementsByClassName == undefined) {
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) {
retnode.push(elem[i]);
}
}
return retnode;
}
};
function tabScroll()
{
var mass = document.getElementsByClassName("locked_left");
var el=0;
for(el=0;el<mass.length;el++)
{
mass[el].style.left = document.getElementById('table_container').scrollLeft;
}
}
</script>
</head>
<body>
<div id='table_container' onscroll="tabScroll()">
<table>
<thead>
<tr>
<th id="locked_left" class='locked_left'>Number</th>
<th >English</th>
<th >French </th>
<th >German </th>
<th>English</th>
<th >French </th>
<th >German </th>
</tr>
</thead>
<tbody>
<tr>
<td id="locked_left" class='locked_left'>1</td>
<td >one</td>
<td >un</td>
<td >eins</td>
<td>one</td>
<td >un</td>
<td >eins</td>
</tr>
<tr>
<td id="locked_left" class='locked_left'>2</td>
<td >two</td>
<td >deux</td>
<td >zwei</td>
<td>one</td>
<td >un</td>
<td >eins</td>
</tr>
<tr>
<td id="locked_left" class='locked_left'>3</td>
<td >three</td>
<td >trois</td>
<td >drei</td>
<td>one</td>
<td >un</td>
<td >eins</td>
</tr>
<tr>
<td id="locked_left" class='locked_left'>4</td>
<td >four</td>
<td >quattre</td>
<td >vier</td>
<td>one</td>
<td >un</td>
<td >eins</td>
</tr>
<tr>
<td id="locked_left" class='locked_left'>4</td>
<td >four</td>
<td >quattre</td>
<td >vier</td>
<td>one</td>
<td >un</td>
<td >eins</td>
</tr>
<tr>
<td id="locked_left" class='locked_left'>4</td>
<td >four</td>
<td >quattre</td>
<td >vier</td>
<td >one</td>
<td >un</td>
<td >eins</td>
</tr>
<tr>
<td id="locked_left" class='locked_left'>4</td>
<td >four</td>
<td >quattre</td>
<td >vier</td>
<td >one</td>
<td >un</td>
<td >eins</td>
</tr>
<tr>
<td id="locked_left" class='locked_left'>4</td>
<td >four</td>
<td >quattre</td>
<td >vier</td>
<td >one</td>
<td >un</td>
<td >eins</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<style type="text/css" media="screen">
#table_container {
width : 200px;
overflow-x:scroll;
overflow-y:visible;
padding-bottom:1px;
margin-left: 60px; /* to make room for position/removed column */
}
table {
border-collapse : collapse;
}
td, th {
background-color: #aaaaaa;
border-right : 1px solid #ffffff;
color : #ffffff;
text-align : center;
width: 60px;
}
.locked_left {
background-color: #88ff88;
font-weight : bold;
border-right : 1px solid #f00;
/* the code below removes the table cells (column) and puts them out to the left of the table */
position:absolute;
left: 0;
top: auto;
margin-left: 2px;
padding-right:4px;
width: 60px; /* needs width here if not given anywhere else */
}
</style>
<!--[if lt IE 8]>
<style type="text/css" media="screen">
.locked_left {
position: relative; /* works better than absolute in IE6 & 7 */
}
#table_container {
margin-left: 0; /* don't need spacing left margin in IE as the column is not actually removed out of the table */
}
</style>
<![endif]-->
<html>
<head>
<title>Some Title</title>
<style type="text/css" media="screen">
#table_container {
width : 100px;
height: 100px;
overflow-x:scroll;
overflow-y:scroll;
padding-bottom:1px;
margin-left: 60px; /* to make room for position/removed column */
margin-top: 32px;
}
table {
border-collapse : collapse;
}
td, th {
background-color: #aaaaaa;
border-right : 1px solid #ffffff;
color : #ffffff;
text-align : center;
width: 60px;
height: 28px;
}
.locked_left {
background-color: #88ff88;
font-weight : bold;
overflow-y:scroll;
border-right : 1px solid #f00;
/* the code below removes the table cells (column) and puts them out to the left of the table */
position:absolute;
left: 0;
top: auto;
margin-left: 2px;
padding-right:4px;
width: 60px; /* needs width here if not given anywhere else */
}
.locked_top {
background-color: #88ff88;
font-weight : bold;
border-bottom : 1px solid #f00;
position:absolute;
top: 0;
left: auto;
margin-top: 2px;
padding-bottom:1px;
height: 28px;
}
</style>
<!--[if lt IE 8]>
<style type="text/css" media="screen">
.locked_left {
position: relative; /* works better than absolute in IE6 & 7 */
}
.locked_top {
position: relative;
}
#table_container {
margin-left: 0; /* don't need spacing left margin in IE as the column is not actually removed out of the table */
margin-bottom: 0;
}
</style>
<![endif]-->
</head>
<body>
<div id='table_container'>
<table>
<thead>
<tr class='locked_top'>
<th>Number</th>
<th >English</th>
<th >French </th>
<th >German </th>
</tr>
</thead>
<tbody>
<tr>
<td class='locked_left'>1</td>
<td >one</td>
<td >un</td>
<td >eins</td>
</tr>
<tr>
<td class='locked_left'>2</td>
<td >two</td>
<td >deux</td>
<td >zwei</td>
</tr>
<tr>
<td class='locked_left'>3</td>
<td >three</td>
<td >trois</td>
<td >drei</td>
</tr>
<tr>
<td class='locked_left'>4</td>
<td >four</td>
<td >quattre</td>
<td >vier</td>
</tr>
<tr>
<td class='locked_left'>4</td>
<td >four</td>
<td >quattre</td>
<td >vier</td>
</tr>
<tr>
<td class='locked_left'>4</td>
<td >four</td>
<td >quattre</td>
<td >vier</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Is there any solution to make this work with CSS and Javascript(May be it is possible to catch scroll event and move corresponding header(column) to a scroll amount)?