table下tbody滚动条与thead对齐的方法且每一列可以不均等
1 前言
table下tbody滚动条与thead对齐的方法,开始在tbody的td和thead的tr>td,对每一个Item加入百分比,结果是没对齐。也尝试了用bootstrap的col-md-1等来对齐,也是对不齐。然后只能网上查找答案了,就只需看用CSS来控制样式即可达到目的
2 代码
核心代码:
<style>
table tbody {
display:block; //core code
height:200px;
overflow-y:scroll;
} table thead, tbody tr {
display:table;
width:100%;
table-layout:fixed;//core code
} table thead {
width: calc( 100% - 1em )//core code
}
</style>
如果只要上面的配置,默认是均等平分table大小的。
完整样例代码如下:
<!DOCTYPE html>
<html>
<head>
<title>Test table tbody is alignment with thead</title>
<style type="text/css">
.per20{
width:20%;
}
.per10{
width:10%;
}
.per40{
width:40%;
} table tbody {
display: block;
height:150px;
overflow:auto;
} table thead, tbody tr {
display:table;
width:100%;
table-layout:fixed;
text-align: left;//If disabled, default align central
} table thead {
width: calc( 100% - 1em )
}
</style>
<script>
window.onload=function(){
var contentSum = "";
for(i = 0; i < 16; i++){
var content = '<tr>'
+ '<td class="per10">'+i+'</td>'
+ '<td class="per10">BBB</td>'
+ '<td class="per20">CCCcontent</td>'
+ '<td class="per10">DDD</td>'
+ '<td class="per40">EEEBigbig</td>'
+ '<td class="per10">FFFXXX</td>'
+'</tr>';
contentSum += content;
}
//$('#content').html(contentSum);
document.getElementById('content').innerHTML=contentSum;
}
</script> </head>
<body> <table border="1px solid" width="900px">
<thead>
<tr>
<th class="per10">A</th>
<th class="per10">BBB</th>
<th class="per20">CCCCCCCCCC</th>
<th class="per10">D</th>
<th class="per40">EEEEEEEEEEEEEE</th>
<th class="per10">FFF</th>
</tr>
</thead>
<tbody id="content">
<!-- <tr>
<td class="per10">1</td>
<td class="per10">BBB</td>
<td class="per20">CCCcontent</td>
<td class="per10">DDD</td>
<td class="per40">EEEBigbig</td>
<td class="per10">FFFXXX</td>
</tr> -->
</tbody>
</table> </body>
</html>
3 效果图

4 参考
http://www.weste.net/2016/01-15/108242.html
table下tbody滚动条与thead对齐的方法且每一列可以不均等的更多相关文章
- CSS设置table下tbody滚动条与thead对齐的方法
<style>table tbody {display:block;height:195px;overflow-y:scroll;} table thead, tbody tr {disp ...
- CSS 设置table下tbody滚动条
table tbody { display:block; height:195px; overflow-y:scroll; } table thead, tbody tr { display:tabl ...
- 向table添加水平滚动条
转自:http://www.cnblogs.com/linjiqin/p/3148225.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. ...
- css实现鼠标移入table时出现滚动条且table内容不移位
一般是这样: 表格的标题和内容分别由一个table组成,其中表格内容的table由一个class="table-body"的div包裹.css如下 .tContainer .tab ...
- 关于jq操作table下多个type=radio的input的选中
假如有2个table: <table id="table1" border="0"> <tr> <td><input ...
- python中selenium操作下拉滚动条方法汇总
UI自动化中经常会遇到元素识别不到,找不到的问题,原因有很多,比如不在iframe里,xpath或id写错了等等:但有一种是在当前显示的页面元素不可见,拖动下拉条后元素就出来了. 比如下面这样一个网页 ...
- chrome和IE下的滚动条样式修改
火狐下的滚动条样式无法去修改,但chorme下的则可以任意修改,惊喜的是IE竟然是最早实现这一功能的浏览器,IE5都能有效果. chorme下的滚动条样式修改: <!DOCTYPE html&g ...
- [Python爬虫] Selenium +phantomjs 模拟下拉滚动条
在爬虫中,有时会遇到这种情况,数据的展示是不是一页一页的,而是通过不断的下拉滚动条来加载数据.例如一点咨询(http://www.yidianzixun.com/)和微博(在未登录的状态下:http: ...
- selenium下拉滚动条
selenium下拉滚动条 制作人:全心全意 谷歌浏览器下拉滚动条 chrome = webdriver.Chrome() //创建谷歌浏览器对象 url="http://www.baidu ...
随机推荐
- read from /dev/urandom 返回值异常
#include<stdio.h> #include<iostream> #include <fcntl.h> #include <sys/mman.h> ...
- Harbor镜像迁移
目录 背景说明 方案实现 背景说明 在早期生产环境尝试使用docker的时候,虽然使用了harbor作为镜像仓库,但是并没有做好相关存储规划,所有的镜像都直接存储到了harbor本地.随着业务发展,本 ...
- spring校验注解
@Null 被注释的元素必须为 null @NotNull 被注释的元素必须不为 null @AssertTrue 被注释的元素必须为 true @AssertFalse 被注 ...
- 面向对象【day08】:类的特殊成员(一)
本节内容 1.__doc__2.__module__和__class__3.__init__4.__del__5 .__call__6 .__dict__7 .__str__8 .__getitem_ ...
- spring整合redis-----ShardedJedisPool实现
redis是一个非常优秀的缓存框架,良好的api,强悍的性能,是现在非常非常火的缓存框架.下面来介绍一下spring中是如何整合redis的 分析: 需要引入依赖 需要配置连接池,就是一个xml文件, ...
- C#设计模式(15)——迭代器模式
1.迭代器模式介绍 迭代器模式主要用于遍历聚合对象,将聚合对象的遍历行为分离出来,抽象为一个迭代器来负责.迭代器模式用的十分普遍,C#/JAVA等高级语言都对迭代器进行了封装用于遍历数组,集合,列表等 ...
- 设置MyBatis在控制台打印SQL语句
在调试阶段,打印SQL会极大方便开发者.MyBatis有提供配置,只需要在MyBatis的配置文件mybatis-config.xml中<configuration>节点下,添加如下配置: ...
- Catfish CMS漏洞集合
转自https://larryxi.github.io/ 0x00 背景 版本:V 4.2.35 官网下载:http://www.catfish-cms.com/page/4.html 文章内容仅作学 ...
- google Guava包的ListenableFuture解析
一. ListenableFuture是用来增强Future的功能的. 我们知道Future表示一个异步计算任务,当任务完成时可以得到计算结果.如果我们希望一旦计算完成就拿到结果展示给用户或者做另外 ...
- Redis 模糊查询删除操作
创建一条测试 数据 查询 创建:set name xiaoming 查询: get name 1.模糊搜索查询 Redis 模糊搜索 keys * 2.删除指定key : # 删除所有以user开头的 ...