【发布时间】:2021-07-05 18:56:50
【问题描述】:
我正在使用 Angular 9。我有一个简单的三列垫表 ...
<mat-table *ngIf="!isMobile" #table [dataSource]="dataSource">
<ng-container matColumnDef="time">
<mat-header-cell *matHeaderCellDef> Time </mat-header-cell>
<mat-cell *matCellDef="let article_stat">{{ getTime(article_stat) }} m</mat-cell>
</ng-container>
<ng-container matColumnDef="score">
<mat-header-cell *matHeaderCellDef> score </mat-header-cell>
<mat-cell *matCellDef="let article_stat">
{{ getscore(article_stat) }} ({{ getWeightedscore(article_stat) }})
</mat-cell>
</ng-container>
<ng-container matColumnDef="article">
<mat-header-cell *matHeaderCellDef> Article </mat-header-cell>
<mat-cell *matCellDef="let article_stat">
<a href='{{ article_stat.article.path }}'>{{ article_stat.article.title }}</a>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" [ngClass]="getRowClass(row)"></mat-row>
</mat-table>
下面是我的组件的简单 CSS。应用组件级别没有 CSS ...
.mat-table {
width: auto;
}
.rising {
font-weight: bold;
}
但是,当我的表格被渲染时,它占据了 100% 的屏幕,尽管事实上每列中的数据并没有占用那么多空间。如果我将宽度更改为固定像素宽度(例如“200px”),浏览器会尊重 wdith。为什么“宽度:自动”不起作用?如何设置 mat-table 的样式,使其只占用与其中的数据一样多的空间?
【问题讨论】:
标签: css html-table width angular9 mat-table