css实现表头部不动
2014-09-12来源:

将下面代码保存为html运行看看

<!doctype html public -//w3c//dtd html 4.0 strict//en>

<html>

<head>

<style>

body {

background-color: #f0f0f0 ;

font: 11px verdana,arial;

width:90%;

margin-left:auto;

margin-right:auto;

}

.tscroll {

border: 1px #7494bf solid;

background-color: #ffffff;

overflow: scroll;

overflow-x:hidden;

height:100px;

cursor: default;

}

tr.tablehead {

position:relative;

background-color:#bfcee7;

height: 16px;

text-align: center;

}

td {

font: 11px verdana, arial;

}

td.asbtn{

border: #7494bf solid;

border-width: 0px 1px 1px 0px;

}

table {

border:0px;

width:100%;

}

</style>

</head>

<body>

<div class=tscroll id=tc>

<table cellspacing=0 cellpadding=0>

<tr class=tablehead onselectstart=return falsestyle=top:expression(document.getelementbyid('tc').scrolltop)>

<td class=asbtn>heading1</td>

<td class=asbtn>heading2</td><td class=asbtn>heading3</td>

<td class=asbtn>heading4</td><td class=asbtn>heading5</td>

<td class=asbtn>heading6</td>

</tr>

<tr><td>cell1</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

<tr><td>cell n</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td><td>cell</td></tr>

</table>

</div>

</body>

</html>

更多信息请查看IT技术专栏

推荐信息
Baidu
map