使用百分比定义mat-card-title宽度

问题描述 投票:1回答:1

我会以mat-card-title文字为中心。所以我需要把它的宽度设置为100%但是我没有得到结果,只有当我使用“px”时。

所以我试图给所有父容器放宽度,但没有结果。

这是我的html文件

<div Fxlaout="row" fxLayoutGap="20px" class="container">
    <div fxFlex=30>
        <mat-card>
            <mat-card-header>
                <mat-card-title>Collaborateurs sur ce projet</mat-card-title>
            </mat-card-header>
            <mat-card-content>

                <mat-list role="list" *ngFor="let per of Projet?.pers">
                    <mat-list-item role="listitem">Nom : {{per.name}}</mat-list-item>
                    <mat-list-item role="listitem">poste : {{per.poste}}</mat-list-item>
                </mat-list>
            </mat-card-content>
        </mat-card>
    </div>
    <div fxFlex>
        <mat-card>
            <mat-card-header>
                <mat-card-title>Les fonctionnalités du produit</mat-card-title>
            </mat-card-header>
            <mat-card-content>
                <mat-list role="list" *ngFor="let func of Projet?.backlog.fonctionnalite; let i=index">
                   <mat-list-item role="listitem">Fonctionnalité #{{i}} : {{func.fonctionnalite}}</mat-list-item>
                </mat-list>
            </mat-card-content>
         </mat-card>
    </div>
</div> 

CSS文件

  mat-card {
    margin-top: 20px;
    margin-bottom: 20px;
    padding: 0;
    width: 100%;
  }
  mat-card-header {
    background-color: #116a94;
    color: white;
    height: 50px;
    width: 100%;
  }

  .container {
    background-color: #87b6bd;
    width: 100%;
  }
  mat-card-title {
    line-height: 50px;
    text-align: center;
    vertical-align: middle;
    width: 100%;
  }

  div {
    width: 100%;
  }

我还在我的app.component.ts中添加了宽度百分比,我调用了我的组件:

<app-navabar></app-navabar>
<div style="width:100%">
   <router-outlet></router-outlet>
</div>

然后我在styles.css文件中添加了width:100%到身体。

我没看到没有宽度为x%的元素在哪里

html css angular angular-material2 md-card
1个回答
3
投票

Angular Material用<mat-card-title>类将<div>包裹在mat-card-header-text中。克服这个问题的一种方法是通过在css中添加以下内容来覆盖类:

/deep/ .mat-card-header-text {
    width: 100%;
    text-align: center; 
}

提示 - 下次遇到类似问题时,使用Google Chrome开发者工具调试已编译的HTML。 Compiled HTML

© www.soinside.com 2019 - 2024. All rights reserved.