首页 > 解决方案 > 修复表头并使表体滚动

问题描述

我在 Angular 项目中工作,但遇到了设计问题

我想滚动表格的主体,使主体标题固定

我试图做 at 但不能只滚动表体

我的代码和设计已准备就绪,我已将其放在下面的链接中 -

https://stackblitz.com/edit/angular-x8c89j?file=src%2Fapp%2Fapp.component.html

标签: htmlcssangularhtml-table

解决方案


请更新您的表格样式如下

table {
  width: 100%;
}

table, td {
  border-collapse: collapse;
  border: 1px solid #000;
}

thead {
  display: table; 
  width: calc(100% - 17px); 
}

tbody {
  display: block; 
  max-height: 200px; 
  overflow-y: scroll;
}

th, td {
  padding: 5px;
  word-break: break-all; 
}

tr {
  display: table; 
  width: 100%;
  box-sizing: border-box; 
}

td {
  text-align: center;
  border-bottom: none;
  border-left: none;
}

tr th:first-child,
tr td:first-child {
  width: 100px;
}

推荐阅读