angular - 我如何居中 Angular Material 表列标题及其 mat-cell 内容

标签 angular angular-material

谁能告诉我如何将 mat table 列标题及其内容居中 这是我的 html 代码

<div fxFlex fxLayout='column' fxLayoutAlign='center center'>
    <mat-form-field>
        <input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
    </mat-form-field>

    <table mat-table [dataSource]="dataSource" matSort class="mat-elevation-z8">


        <ng-container matColumnDef="date">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Date </th>
            <td mat-cell *matCellDef="let element"> {{element.date | date}} </td>
        </ng-container>


        <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
        <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
    </table>
    <mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
</div>

我在小屏幕上得到这样的结果

enter image description here

大屏enter image description here

最佳答案

将以下样式添加到全局 styles.scss 文件中:

th.mat-header-cell,
td.mat-cell {
  text-align: center !important;
}

Working stackblitz example

关于angular - 我如何居中 Angular Material 表列标题及其 mat-cell 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59268987/

相关文章:

javascript - Angular Material $mdDialog.confirm 具有超过 "OK"和 "Cancel"选项

javascript - 将事件向下传递给 Angular 2 应用程序中不是另一个组件的父组件或子组件

css - 在 Ionic 4 输入表单中,如何更改日期文本的输入颜色?

angular - 使用具有链接的 firebase 值的 Angular Material mat-select 组件中的 compareWith 函数

Angular Material mat-form-field 多行占位符文本

angularjs - 为什么Angular Material ngToast会让页面跳转?

javascript - 尝试使用双向数据绑定(bind)使用指令中的自定义代码更改 Material md-selected 选项卡

css - :host selector for angular-material dialog

angular - 在 angluar2 webpack 中使用 Font-awesome

css - 如何删除下拉菜单上的填充