table头部、尾部固定;中间内容定高自适应滚动
table头部、尾部固定;中间内容定高自适应滚动
很多时候,需要使用到表格做数据分析,不管是前端展现,还是后台管理系统节点展现
工作过程中遇到了,作为一个小笔记,备忘!
如下图所示
---------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
表格的头部,和尾部是固定不动的,中间内容随着内容的增多,而出现滚动条。
<!--container-->
<div class="container">
<table class="form-table" cellpadding="0" cellspacing="0">
<thead class="fixed-thead" id="head">
<tr>
<th>序号</th>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
</tr>
</thead>
<tbody class="scroll-tbody" id="body">
<tr>
<td>1</td>
<td>张三</td>
<td>男</td>
<td>18</td>
</tr>
</tbody>
<tfoot class="fixed-tfoot">
<tr>
<td>序号</td>
<td>姓名</td>
<td>性别</td>
<td>年1龄</td>
</tr>
</tfoot>
</table>
</div>
<!--container-->
如上html结构简单。精简。
/*各个部分样式*/
@charset "utf-8";
body{
overflow: hidden;
}
.container {
border: 1px #ccc solid;
width: 90%;
margin: 100px auto;
}
.form-table {
width: 100%;
border-collapse: collapse;
margin: 0 auto;
text-align: center;
table-layout: fixed;
}
.form-table th {
border-left: none;
border-top: none;
border-right: 1px #ccc solid;
border-bottom: 1px #ccc solid;
background: #F3F3F3;
}
.form-table td {
border-left: none;
border-top: none;
border-bottom: 1px #ccc solid;
border-right: 1px #ccc solid;
}
.fixed-thead,
.fixed-tfoot {
display: block;
/*width: 99%;*/
width: -webkit-calc(100% - 17px);
width: -moz-calc()(100% - 17px);
width: calc(100% - 17px);
height: 50px;
}
.fixed-tfoot tr td {
background: #F3F3F3;
border-bottom: none;
}
.fixed-thead tr,
.fixed-tfoot tr {
width: 100%;
height: 50px;
line-height: 50px;
display: block;
}
.fixed-thead tr th,
.fixed-tfoot tr td {
float: left;
display: block;
width: 25%;
height: 50px;
font-size: 16px;
text-align: center;
}
.scroll-tbody {
display: block;
height: 306px;
overflow: auto;
width: 100%;
}
.scroll-tbody tr {
width: 100%;
display: block;
height: 40px;
line-height: 40px;
}
.scroll-tbody tr td {
float: left;
display: block;
width: 25%;
}
.form-table .scroll-tbody tr:nth-child(odd) td {
background-color: #ECE9D8;
}
-------------------核心对齐样式---------------------
width: -webkit-calc(100% - 17px);
width: -moz-calc()(100% - 17px);
width: calc(100% - 17px);
兼容高级浏览器
-----------------------------------------------------
为了兼容IE6,可以使用如下 js去实现
<script type="text/javascript">
window.onload=window.onresize=function (){
var body=document.getElementById("body");
var head=document.getElementById("head");
head.style.width=(body.scrollWidth)+"px";
}
</script>
----------------------------------------------------
table头部、尾部固定;中间内容定高自适应滚动的更多相关文章
- layui table 数据表格固定列的行高和table其他列的行高不一致
1.问题描述:使用layui的table数据表格,固定某一列,这样表格中数据的宽度超出屏幕宽度时,固定列可以一直显示在屏幕中,不会随着底部滚动栏左右的拖动而变化位置.但是遇到一个问题,就是固定列的行高 ...
- flex盒模型实现头部尾部固定
近期做移动app.wap等站,需要头部固定在顶部,不随着内容滚动而滚动平时第一想法就是使用position:fixed;top:0;z-index:10;这样去实现但这样使用fixed之后,会在ios ...
- table 与 div 固定宽高问题
div {width:100px;height:200px;word-wrap: break-word;overflow:hidden;} 这个可以固定div的宽高,溢出内容会被剪除. table{t ...
- table表格宽度固定,同时td内容过长也不会被撑开
table表格宽度固定,同时td内容过长也不会被撑开,设置如下css: table{table-layout:fixed;word-break:break-all;}
- html Table实现表头固定
最近一直在搞前台琐碎的东西,也学习了一下linux,没有时间对新的东西进行深入的研究和学习,没有写博客,不过归咎其原因还是在于自己的惰怠. 废话不多说,今天想将一个前台页面设计的一个小东西分享一下,那 ...
- LODOP打印table表格宽度固定-超宽隐藏
之前有博文介绍关于超出div隐藏内容的:LODOP打印超过后隐藏内容样式里面提到了overflow:hidden;控制超出后隐藏,但是前面那篇用的是div,如果是在table中,由于table默认的t ...
- table表格某一td内容太多导致样式混乱的解决方案
对于有很多条目的数据,通常采用table元素来快速实现,某一个td的内容太多的话就会导致样式混乱难看. 解决方案 要让table的宽度固定可以给table元素设置table-layout:fixed; ...
- margin+absolute布局:右栏固定主内容自适应 demo
margin+absolute布局:右栏固定主内容自适应 demo 头部 Aside侧边栏区域 Main主内容区域 底部 #demo{width:80%;margin:auto;height:300p ...
- bootstrap table实现iview固定列的效果
因为bootstrap自带的固定列效果满足不了公司需求,所以借助fixed-table这个插件完成了iview固定列的效果 <!DOCTYPE html> <html lang=&q ...
随机推荐
- Xcode升后插件失效
Xcode升后插件失效,与添加插件不小心点击Skip Bundle解决办法 字数267 阅读4731 评论1 喜欢12 今天升级了xcode到6.4 发现之前装的插件不能使用了.这里有一个解决的方案: ...
- iOS 常见错误:CALayer position contains NaN: [14 nan]
Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contai ...
- sql uniqueidentifier转varchar
--- DECLARE @myid uniqueidentifierSET @myid = NEWID()SELECT CONVERT(char(255), @myid) AS 'char';GO-- ...
- 九、C# 合式类型
本章要描述如何最终完善类型声明. 1.重写Ojbect中的成员 重写ToString() 默认情况下,在任何对象上调用 ToString()会返回类的完全限定名称,所以有时候需要重载这个函数, ...
- Spring MVC中注解 @ModelAttribute
1.@ModelAttribute放在方法之上,在当前Control内的所有方法映射多个URL的请求,都会执行该方法 @ModelAttribute public void itemsCommon(H ...
- hdoj 2041 超级阶梯
代码: #include <stdio.h>int main(){int n;int i;int m;int count;int dp[50];while(scanf("%d&q ...
- 通过C# 打开一个应用程序
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo(); //设置外部程序名 Info ...
- Winform控件Enable=false显示优化
在B/S开发中(ASP.NET),往往可以css样式表来让页面控件更加美观,但是在C/S中(Winform)里面,我们则需要通过其他取巧的 方式来实现.例如:当你因为某个需求需要将控件设置为Reado ...
- 自定义Excel导出简易组件
1.组件原理 excel的数据存储是以xml格式存储的,所以导出Excel文件可以通过生成XML来实现.当然XML必须符合一定的格式要求. 2.组件实现 (1)新建类库文件“MyExcel” (2)添 ...
- javascript为目标标签添加class样式
利用jQuery $("#目标id").addClass("加的class名字");