css - 如何固定 mat-cell 的高度并将其设置为溢出?
问题描述
我创建了一个带有这样一列的 mat 表:
<div class='table-container mat-elevation-z8'>
<table mat-table [dataSource]="dataSource">
<!-- Position Column -->
<ng-container matColumnDef="summary">
<th mat-header-cell *matHeaderCellDef> Summary </th>
<td mat-cell *matCellDef="let element" [innerHTML] ='element.summary'></td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
我像这样输入css:
.mat-row{
white-space:nowrap;
height:48px;
max-height:48px;
overflow: hidden;
overflow-y:hidden;
text-overflow: hidden;
}
.mat-cell{
white-space:nowrap;
height:48px;
max-height:48px;
overflow: hidden;
overflow-y:hidden;
text-overflow: hidden;
}
但是高度和溢出不起作用,行高仍然由身体自动增长:
我确实尝试了 ::ng-deep 和 !important 但仍然无法正常工作
我怎样才能做到?
解决方案
由于td
属性是表格单元格,block
所以你不能让它滚动替代解决方案是你需要将你的信息包装在一些div
里面overflow :auto
并将它放在里面td
然后 div 可以滚动
就像在你的.ts
HTML
<div class='data-wrap'>
Some data
</div>
CSS
.data-wrap{
white-space:nowrap;
height:48px;
max-height:48px;
overflow: hidden;
overflow-y:hidden;
text-overflow: hidden;
}
推荐阅读
- kubernetes - 可以将在容器/pod 中运行的程序的配置放在 Deployment yaml 中而不是 ConfigMap yaml 中吗?
- bash - 循环遍历不同的目录并更改文件名
- mysql - 在 cakephp 3 中添加包含模型的多个计数字段以进行查询
- kotlin - Ktor application.conf - Jwt 配置
- reactjs - 如何安装 react (v16.x) 和 react-scripts (3.x)
- javascript - 是否可以缩短 javascript 以避免 if 和 else?
- ruby-on-rails - 将复杂哈希传递给 Sidekiq 作业
- python - 使用 pip 安装旧版本的 sklearn
- python - 来自烧瓶的响应在 React 前端收到的 Json 上有额外的密钥
- laravel - spatie / laravel-translatable 在我尝试检索尚不存在的翻译时显示默认语言环境