1 回答
TA贡献1719条经验 获得超6个赞
如果您只是希望第一列可折叠并具有不同的样式,则可以完全移除滑块。这是一个关于如何折叠第一列并为其设置样式的基本示例:
var table = document.getElementById('usertable');
var toggleCollapsed = function(e) {
if (table.classList.contains('collapsed')) {
table.classList.remove('collapsed');
} else {
table.classList.add('collapsed');
}
}
table.addEventListener('click', toggleCollapsed)
table td:first-child {
background-color: black;
color: white;
}
table td:first-child i {
margin-right: 5px;
}
table.collapsed td:first-child {
text-align:center;
}
table.collapsed td:first-child i {
margin-right: 0;
}
table.collapsed td:first-child .username {
display: none;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<table id="usertable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td><span class="username">Name</span></td>
<td>AAAAAAAAAAAAAA</td>
<td>BBBBBBBBBBBBBB</td>
<td>CCCCCCCCCCCCCC</td>
<td>DDDDDDDDDDDDDD</td>
<td>EEEEEEEEEEEEEE</td>
</tr>
</thead>
<tbody>
<tr>
<td><i class="far fa-user"> </i><span class="username">Adelfried</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><i class="far fa-user"> </i><span class="username">Kalona</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><i class="far fa-user"> </i><span class="username">Raynard</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><i class="far fa-user"> </i><span class="username">Wesley</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><i class="far fa-user"> </i><span class="username">Theobald</span></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
添加回答
举报