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对齐的方法且每一列可以不均等的更多相关文章

  1. CSS设置table下tbody滚动条与thead对齐的方法

    <style>table tbody {display:block;height:195px;overflow-y:scroll;} table thead, tbody tr {disp ...

  2. CSS 设置table下tbody滚动条

    table tbody { display:block; height:195px; overflow-y:scroll; } table thead, tbody tr { display:tabl ...

  3. 向table添加水平滚动条

    转自:http://www.cnblogs.com/linjiqin/p/3148225.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. ...

  4. css实现鼠标移入table时出现滚动条且table内容不移位

    一般是这样: 表格的标题和内容分别由一个table组成,其中表格内容的table由一个class="table-body"的div包裹.css如下 .tContainer .tab ...

  5. 关于jq操作table下多个type=radio的input的选中

    假如有2个table: <table id="table1" border="0"> <tr> <td><input ...

  6. python中selenium操作下拉滚动条方法汇总

    UI自动化中经常会遇到元素识别不到,找不到的问题,原因有很多,比如不在iframe里,xpath或id写错了等等:但有一种是在当前显示的页面元素不可见,拖动下拉条后元素就出来了. 比如下面这样一个网页 ...

  7. chrome和IE下的滚动条样式修改

    火狐下的滚动条样式无法去修改,但chorme下的则可以任意修改,惊喜的是IE竟然是最早实现这一功能的浏览器,IE5都能有效果. chorme下的滚动条样式修改: <!DOCTYPE html&g ...

  8. [Python爬虫] Selenium +phantomjs 模拟下拉滚动条

    在爬虫中,有时会遇到这种情况,数据的展示是不是一页一页的,而是通过不断的下拉滚动条来加载数据.例如一点咨询(http://www.yidianzixun.com/)和微博(在未登录的状态下:http: ...

  9. selenium下拉滚动条

    selenium下拉滚动条 制作人:全心全意 谷歌浏览器下拉滚动条 chrome = webdriver.Chrome() //创建谷歌浏览器对象 url="http://www.baidu ...

随机推荐

  1. [luoguU42591][小T的绝对值]

    luoguU42592 20分思路 对给出的序列求出前缀和,然后\(n^2\)暴力枚举即可拿到第一档分 40分思路 对于数列中的数都相同的情况.只需要特判即可.只要特别注意全都是0的情况即可. 100 ...

  2. mysql常见问题解决

    日常使用mysql数据库遇到的一些问题,做下记录,会持续更新. 一.MySql Host is blocked because of many connection errors; unblock w ...

  3. Histogram of Oriented Gridients(HOG) 方向梯度直方图

    Histogram of Oriented Gridients,缩写为HOG,是目前计算机视觉.模式识别领域很常用的一种描述图像局部纹理的特征.这个特征名字起的也很直白,就是说先计算图片某一区域中不同 ...

  4. 树莓派 3b 串口启用

    网上搜到的方法都没用,不知道是不是系统版本的原因.以下方法是试出来的... uname -aLinux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:5 ...

  5. AE与C#入门笔记

    http://www.cnblogs.com/e3e4/articles/3695214.html

  6. 聊一聊docker存储驱动

    目录 镜像的分层特性 容器读写层的工作原理 写时复制 用时配置 Docker存储驱动 AUFS OverlayFS Devicemapper 常用存储驱动对比 AUFS VS OverlayFS Ov ...

  7. javascript 获取节点元素的封装

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. filebeat多个key

    filebeat.prospectors:- type: log paths: - D:\logs\iis\W3SVC2\*.log exclude_lines: ['^#'] multiline: ...

  9. zabbix微信预警出现的问题

    系统环境:centos7.3 zabbix_server: 3.0.3 3.0.6 问题描述 zabbix预警突然不能发送微信,需要修复 排查步骤 1. 检查微信企业平台应用的key是否过期,结果没过 ...

  10. JAVA实现具有迭代器的线性表(顺序表)

    1,先了解下JAVA类库中的迭代器:JAVA提供了两种基本类型的迭代器,分别用两个接口来表示:Iterator<T>,ListIterator<T>.其中,Iterator&l ...