Angular material 垫表如何将垫头与垫单元宽度对齐

Angular material 垫表如何将垫头与垫单元宽度对齐,angular-material,alignment,mat-table,Angular Material,Alignment,Mat Table,我是flex的新手,我的垫子桌子做得很好。 不幸的是,我的标题没有跟随我的单元格宽度 这是我成绩的照片 正如您所看到的,我的标题与单元格不对齐 这是我的CSS代码,就像我说的我是新来的,所以我可能错过了一些东西 @import "./../../styles.scss"; .mat-header-row { width: 100%; min-height: 20px; padding: 0px 0px 0px 4px; } .mat-row { width: 10

我是flex的新手,我的垫子桌子做得很好。 不幸的是,我的标题没有跟随我的单元格宽度

这是我成绩的照片

正如您所看到的,我的标题与单元格不对齐

这是我的CSS代码,就像我说的我是新来的,所以我可能错过了一些东西

@import "./../../styles.scss";


.mat-header-row {
    width: 100%;
  min-height: 20px;
  padding: 0px 0px 0px 4px;
}

.mat-row {
    width: 100%;
  min-height: 12px;
  display: inline-flex;
 // min-width: 100%;
}

.mat-header-cell {
  justify-content: left;
  font-size: smaller;
  font-weight: bold;
  padding: 0px 0px 0px 4px;
}

.mat-cell {
  justify-content: left;
  border-top: 1px solid crimson;
  font-size: smaller;
  padding: 0px 0px 0px 4px;
  text-align: left;
  align-items: flex-start;
}

.mat-cell-points {
  flex: 0 0 20px !important;
  white-space: unset !important;
}

.mat-cell-concession{
    flex: 0 0 200px !important;
    white-space: unset !important;
  justify-content: left;
  border-top: 1px solid crimson;
  font-size: smaller;
  padding: 0px 0px 0px 4px;
  text-align: left;
}

.rcorner1 {
  border-radius: 25px;
  background: mat-color($accent, 300);
  padding: 20px;
}

.example-container {
  display: flex;
  flex-direction: column;

  // min-width: 200px;
  max-width: 380px;
}


label {
  min-width: 15%;
}

.mat-row:nth-child(1n + 1) {
    background-color: mat-color($accent, lighter);
  }

  .mat-row:not(:nth-child(2n + 1)) {
    background-color: mat-color($primary, 300);
  }

.example-element-row:hover {
  background: mat-color($accent, 800);
}
.example-element-row:active {
  background: #efefef;
}
和我的HTML代码:

<div class="example-container mat-elevation-z8 alternate-theme mat-app-background" color="primary">
    <div class="mat-header-cell">
        {{ this.getTypeInfo(this.typeList.TypeBourse) }}
    </div>
    <mat-table [dataSource]="bourseDetail" class="mat-elevation-z8">
        <!-- https://stackoverflow.com/questions/53084892/angular-material-table-cell-formatting/53096778 -->
        <!-- Position Column -->
        <ng-container matColumnDef="Position">
            <mat-header-cell *matHeaderCellDef matTooltip="Position"> # </mat-header-cell>
            <mat-cell *matCellDef="let element">{{ element.Position }}</mat-cell>
        </ng-container>

        <!-- Concession Column -->
        <ng-container matColumnDef="nom">
            <mat-header-cell *matHeaderCellDef>Concession</mat-header-cell>
            <mat-cell class="mat-cell-concession" *matCellDef="let element">
                <ng-container *ngIf="element.Concession.Nom; else elseBlock">
                    {{ element.Concession.Nom }}
                    <ng-template #elseBlock>Content to render when condition is false.</ng-template>
                </ng-container>
            </mat-cell>
        </ng-container>

        <!-- Points Column -->
        <ng-container matColumnDef="Points">
            <mat-header-cell *matHeaderCellDef>points</mat-header-cell>
            <mat-cell *matCellDef="let element">{{ element.Points }}</mat-cell>

        </ng-container>

        <!-- Amount Column -->
        <ng-container matColumnDef="Montant">
            <mat-header-cell *matHeaderCellDef>Gain</mat-header-cell>
            <mat-cell *matCellDef="let element">{{ element.Montant | currency }}</mat-cell>

        </ng-container>

        <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
        <mat-row *matRowDef="let row; columns: displayedColumns" class="example-element-row"></mat-row>
    </mat-table>
</div>

{{this.getTypeInfo(this.typeList.TypeBourse)}
# 
{{element.Position}
让步
{{element.devention.Nom}
条件为false时要渲染的内容。
要点
{{element.Points}}
获得
{{element.Montant | currency}}

感谢您的帮助

以下是我现在可以使用的代码:

<div class="example-container mat-elevation-z8 alternate-theme mat-app-background" color="primary"
style="width: 450px;">
<div class="div-title">
    {{ this.annee }} - {{ this.getTypeInfo(this.typeList.TypeBourse) }}
</div>
<mat-table [dataSource]="bourseDetail" class="mat-elevation-z8">
    <!-- https://stackoverflow.com/questions/53084892/angular-material-table-cell-formatting/53096778 -->
    <!-- Position Column -->
    <ng-container matColumnDef="Position">
        <mat-header-cell class="mat-cell" *matHeaderCellDef matTooltip="Position"> Pos </mat-header-cell>
        <mat-cell class="mat-cell-column" *matCellDef="let element">{{ element.Position }}</mat-cell>
    </ng-container>

    <!-- Concession Column -->
    <ng-container matColumnDef="nom">
        <mat-header-cell class="mat-cell-concession" *matHeaderCellDef>Concession</mat-header-cell>
        <mat-cell class="mat-cell-concession mat-cell-column" *matCellDef="let element">
            <ng-container *ngIf="element.Concession.Nom">
                {{ element.Concession.Nom }}
                                                                                                
            </ng-container>
            <ng-container *ngIf="!element.Concession.Nom">
                Info manquante
            </ng-container>
        </mat-cell>
    </ng-container>

    <!-- Points Column -->
    <ng-container matColumnDef="Points">
        <mat-header-cell class="mat-cell" *matHeaderCellDef>points</mat-header-cell>
        <mat-cell class="mat-cell-column" *matCellDef="let element">{{ element.Points }}</mat-cell>

    </ng-container>

    <!-- Amount Column -->
    <ng-container matColumnDef="Montant">
        <mat-header-cell class="mat-cell" *matHeaderCellDef>Gain</mat-header-cell>
        <mat-cell class="mat-cell-column" *matCellDef="let element">{{ element.Montant | currency }}</mat-cell>

    </ng-container>

    <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
    <mat-row *matRowDef="let row; columns: displayedColumns" class="example-element-row"></mat-row>
</mat-table>

您同时找到解决方案了吗?我提交了一个答案,代码现在正在运行。(更快地发送解释它的代码…因为我在1年前制作了它)
    .mat-table {
      width: 100%;
    }

    .mat-row {
        width: 100%;
        min-height: 12px;
    }

    .div-title {
        text-align: center;
        font-size: medium;
        font-weight: bold;
        padding: 4px;
      }
      
    .mat-header-cell {
        min-height: 12px;
        font-size: smaller;
        font-weight: bold;
    }

    .mat-header-row {
      width: 100%;
      min-height: 10px;
      padding: 0px 0px 0px 4px;
    }
     
    .mat-cell-column {
        border-top: 1px solid crimson;
    }

    .mat-cell {
        flex: 0 0 50px !important;
        white-space: unset !important;
        justify-content: left;
        font-size: smaller;
        padding: 0px 0px 0px 4px;
        text-align: left;
    }

    .mat-cell-concession {
        flex: 0 0 250px !important;
        min-width: 250px !important;
        white-space: unset !important;
        justify-content: left;
        font-size: smaller;
        padding: 0px 0px 0px 4px;
        text-align: left;
        color: black;
    }

    .mat-row:nth-child(1n + 1) {
        background-color: mat-color($accent, lighter);
      }
      
      .mat-row:not(:nth-child(2n + 1)) {
        background-color: mat-color($primary, 300);
      }

    .example-element-row:hover {
      background: mat-color($accent, 800);
    }
    .example-element-row:active {
      background: #efefef;
    }