您可以将 CSS 与 Flexbox 结合使用,通过在导航栏、搜索和表格部分中适当地设置flex-grow
和属性来使表格填满剩余的屏幕空间。flex-shrink
然后使用绝对定位的 divoverflow: auto
来包裹你的桌子。
HTML:
<div id="container">
<div id="navbar"></div>
<div id="search"></div>
<div id="table">
<div id="table-container">
<!-- Table goes here -->
</div>
</div>
</div>
CSS:
#container {
height: 100vh;
display: flex;
flex-direction: column;
position: relative;
}
#navbar {
flex: 0 0 auto;
height: 70px;
width: 100%;
}
#search {
flex: 0 0 auto;
height: 50px;
width: 100%;
}
#table {
flex: 1 1 auto;
width: 100%;
position: relative;
}
#table-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
overflow: auto;
}
#table-container table {
width: 100%;
}
对于奖励积分,添加position: sticky
以将表格标题固定在滚动条上:
.mat-header-row th {
position: sticky;
top: 0;
background-color: white;
}
Stackblitz 演示在这里:https ://stackblitz.com/edit/angular-ykwfsy