【发布时间】:2017-07-06 16:11:56
【问题描述】:
我在将两个 html 表格与两列垂直对齐时遇到问题。相关的html和css代码可以看这个jsfiddle
这里是相关的css:
.users-container{
width: 200px;
height: auto;
margin: 0;
padding: 0;
float: left;
overflow:hidden;
border: 1px solid #99CCFF;
}
.users-filter{
width: 100%;
height: 20px;
border: none;
border-bottom:1px solid #99CCFF;
}
.users-header{
width: 100%;
height: auto;
margin: 0;
padding: 0;
overflow: hidden;
}
.users-header table{
width: 100%;
height: auto;
border-collapse: collapse;
}
.users-header table td{
padding: 3px 0;
background-color: #99CCFF;
color: white;
vertical-align: center;
}
.users-header table td:nth-child(1){
text-align: center;
border-top: 1px solid #2E8AE6;
border-right: 1px solid #2E8AE6;
border-bottom: 1px solid #2E8AE6;
}
.users-header table td:nth-child(2){
text-align: left;
padding-left: 10px;
border-top: 1px solid #2E8AE6;
border-bottom: 1px solid #2E8AE6;
}
.users-list{
width: 100%;
height: auto;
margin: 0;
padding: 0;
max-height: 200px;
overflow: auto;
}
.users-list table {
width: 100%;
height: auto;
border-collapse: collapse;
}
.users-list table td{
padding: 3px;
border-bottom: 1px solid #99CCFF;
vertical-align: center;
}
.users-list table td:nth-child(1){
text-align: center;
}
.users-list table td:nth-child(2){
text-align: left;
padding-left: 10px;
}
正如您在结果窗口中看到的,顶部“标题”表中的复选框列未与底部表的复选框列对齐。即使css几乎相同,顶部表格中复选框的大小也与底部不同。我做错了什么?
我想在允许滚动底部表格的同时保持标题固定。我不想使用 jQuery 或任何其他工具包。
我们将不胜感激。
【问题讨论】:
-
固定表头的纯 CSS 解决方案并不是那么简单,但我还是找到了一个相关的解决方案:codepen.io/tjvantoll/pen/JEKIu 现在由您来决定是否适合您的情况。
-
感谢您的回复,但我尝试在括号中使用相同的代码,但格式不正确。
标签: html css vertical-alignment css-tables