参考:博客园 zeroz
https://www.cnblogs.com/zerozq/p/9138320.html
table tbody {
max-height: 500px;
display: block;
overflow-y: auto;
}
table thead, table tbody tr {
width: 100%;
display: table;
table-layout: fixed;
}
table thead {
width: calc(100% - 3px); /*减去默认滚动条的宽度,让thead 与tbody 对齐*/
}
table tbody::-webkit-scrollbar { width: 3px;} /*设置滚动条的宽度,让thead 与tbody 对齐*/
/*改变滚动条的宽度和样式*/
table tbody::-webkit-scrollbar { width: 3px;}
table tbody::-webkit-scrollbar-track{background-color:#f0f0f0;}
table tbody::-webkit-scrollbar-thumb{background-color:#CCCCCC;}
table tbody::-webkit-scrollbar-thumb:hover {background-color:#CCCCCC;}
table tbody::-webkit-scrollbar-thumb:active {background-color:#CCCCCC;}
效果:
使用前:
使用后: