【问题标题】:content inside mat-card isn't centred using flexmat-card 中的内容未使用 flex 居中
【发布时间】:2019-03-18 22:38:42
【问题描述】:

我正在使用有棱角的材料来展示一张卡片, 我希望卡片内的内容水平居中, 即使我添加了`justify-content: flex-start;它不会使卡片内的内容相互水平,它总是粘在左边

这是我的 HTML

<!-- Classes main-div and example-card are categorised in .css file -->
<div class="main-div">
  <mat-card class="example-card">
    <mat-card-header>
      <div class="login-box-header">
          <!-- Src image is temporary hosted in image.ibb-->
          <img src="https://image.ibb.co/hDqa3p/codershood.png">
      </div>
    </mat-card-header>
    <mat-card-content>
      <form>
        <table>
          <tr>
            <td>
              <mat-form-field>
              <input matInput placeholder="Username" [(ngModel)]="username" name="username" required>
              </mat-form-field>
            </td>
          </tr>
          <tr>
          <td><mat-form-field>
            <input matInput placeholder="Password" [(ngModel)]="password"type="password" name="password" required>
          </mat-form-field></td>
        </tr></table>
      </form>
      <mat-spinner [style.display]="showSpinner ? 'block' : 'none'"></mat-spinner>
    </mat-card-content>
    <mat-card-actions>
      <button mat-raised-button (click)="login()" color="primary">Login</button>
    </mat-card-actions>
  </mat-card>

</div>

这是我的 CSS 文件:

.example-card {
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
}

.main-div{
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

我正在使用有角度的材料,角度。

如何让卡片内的内容居中?

谢谢

【问题讨论】:

标签: html css angular flexbox angular-material


【解决方案1】:

你可以试试这样的:

.example-card * {
  align-self: center;
}

:)

【讨论】:

  • 没有帮助,我试过了它仍然与左边对齐
  • 奇怪。对我来说,它正在工作。您是否使用“ * ”添加了新的 css 规则?
  • 基本上 align-items 对齐子元素。 align-self 对齐它自己的元素。你已经以孩子为中心,但不是内在的孩子。所以这样所有的孩子都将他们自己对齐在中心
猜你喜欢
  • 2019-05-22
  • 1970-01-01
  • 2018-11-08
  • 2019-03-12
  • 1970-01-01
  • 2010-12-19
  • 2017-02-16
  • 2019-07-25
  • 1970-01-01
相关资源
最近更新 更多