在我们的应用程序中,我们有一个表,其中没有动态的行和列。.同一指令用于显示两个不同的表。我向表中添加了一个叠加滚动条...在chrome中工作正常,但在Mozilla和IE中却无法正常工作。.在两种浏览器中,它的行为都像普通滚动条,并导致未对齐..有人可以帮助我吗..其他解决方案,以避免工作台未对齐。 https://jsfiddle.net/KrishnaAnanthi/t1vna5uz/
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
th,
td {
padding: 5px;
}
.filter-container {
width: 100%;
height: 100%;
position: relative;
padding: 0px !important;
margin: 0px !important;
}
.header-container {
height: 100%;
vertical-align: middle;
text-align: center;
overflow: hidden;
}
.header-text {
font-size: 22px;
line-height: 24px;
}
.header-text {
color: #000000;
font-weight: normal;
word-break: break-all;
}
tbody.scrollContent {
max-height: 100px;
overflow-x: hidden;
overflow-y: overlay;
background-color: white;
}
tbody {
display: block;
}
.header-text {
width: 90%;
float: left;
text-align: start;
letter-spacing: 0;
text-align: left;
}
.icon-right {
position: absolute;
top: 50%;
right: 0;
margin-top: -10px;
}
.sort-icon {
float: right !important;
clear: right;
height: 1px !important;
}
thead,
tbody tr {
display: table;
width: 100%;
table-layout: fixed;
}
<table style="width:80%">
<thead>
<tr>
<th>
<div class='filter-container header-container'>
<div class='header-text'> Name of station </div>
<div class='icon-right'> <span class="fa fa-sort-asc fa-lg sort-icon "></span><span class="fa fa-sort-desc fa-lg sort-icon "></span></div>
</div>
</th>
<th>
<div class='filter-container header-container'>
<div class='header-text'> lastname</div>
<div class='icon-right'> <span class="fa fa-sort-asc fa-lg sort-icon "></span><span class="fa fa-sort-desc fa-lg sort-icon "></span></div>
</div>
</th>
<th>
<div class='filter-container header-container'>
<div class='header-text'> Age</div>
<div class='icon-right'> <span class="fa fa-sort-asc fa-lg sort-icon "></span><span class="fa fa-sort-desc fa-lg sort-icon "></span></div>
</div>
</th>
<th>
<div class='filter-container header-container'>
<div class='header-text'> Address</div>
<div class='icon-right'> <span class="fa fa-sort-asc fa-lg sort-icon "></span><span class="fa fa-sort-desc fa-lg sort-icon "></span></div>
</div>
</th>
<th>
<div class='filter-container header-container'>
<div class='header-text'> Hobby</div>
<div class='icon-right'> <span class="fa fa-sort-asc fa-lg sort-icon "></span><span class="fa fa-sort-desc fa-lg sort-icon "></span></div>
</div>
</th>
</tr>
</thead>
<tbody class='scrollContent'>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
<td>Bangalore</td>
<td>Playing</td>
</tr>
</tbody>
</table>
答案 0 :(得分:0)
实际上,当我们动态设置表格宽度并设置溢出滚动时,我们可以获得预期的结果。并且必须为除最后一列之外的所有列设置宽度。 假设我们有5列的表格,我们需要为前四列设置宽度,第五列将自动调整
#table_id thead tr th:nth-child(2),
#table_id thead tr th:nth-child(3),
#table_id thead tr th:nth-child(4),
#table_id tbody tr td:nth-child(2),
#table_id tbody tr td:nth-child(3),
#table_id tbody tr td:nth-child(4) {
width: calc((100vw - 150px) / 4);
}