项目中设计的报表table设计的列数相对过多,当拖动下方的滚动条时无法对应表头所对应的列,因此在网上搜索了好一段日子,最后在网上找到了一些参考资料,然后总结归纳出兼容行列合并的固定表头demo。
多浏览器没有做太多测试,但是在ie9、火狐、360浏览器中已测试通过。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>固定table表头</title>
<style type="text/css">
.div1All{
position: absolute;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px
}
.divHeaderID{
margin-right: auto;
margin-left: auto;
overflow: hidden;
bgcolor: blue;
}
.divContentID{
position: absolute;
left: 0px;
top: 30.5px;
bottom: 0px;
right: 0px;
overflow: scroll
}
</style>
</head>
<body>
<div class="div1All">
<div class="divHeaderID">
<table border="1" cellspacing="0">
<Tr style="height: 30px">
<Th width="100px">Header A</Th>
<Th width="100px">Header B</Th>
<Th width="100px">Header C</Th>
<Th width="100px">Header D</Th>
<Th width="100px">Header E</Th>
<Th width="100px">Header F</Th>
</Tr>
</table>
</div>
<div class="divContentID">
<table border="1" cellspacing="0" >
<c:forEach begin="1" end="100" varStatus="index">
<Tr>
<Td width="100px">${index.index}</Td>
<Td width="100px">B</Td>
<Td width="100px">C</Td>
<Td width="100px">D</Td>
<Td width="100px">E</Td>
<Td width="100px">F</Td>
</Tr>
</c:forEach>
</table>
</div>
</div>
</body>
</html>