【问题标题】:How to center align card in angular material 4?如何在角材料 4 中居中对齐卡片?
【发布时间】:2017-12-26 00:27:00
【问题描述】:

我创建了一个带有角材料的示例 Angular 4 应用程序。 我正在尝试将卡片置于视图的中心。 但它不起作用。下面是代码

app.component.html

<!--The content below is only a placeholder and can be replaced.-->
<router-outlet></router-outlet>

login.component.html

<div  ng-cloak=""  layout-fill layout="column" style="background:green" layout-align="center">
    <div flex="50" layout="row" layout-align="center">
      <md-card flex="50"></md-card>
    </div>
</div>

login.component.ts

import { Component, OnInit } from '@angular/core';
import { MdCardModule,MdInputModule } from '@angular/material';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

【问题讨论】:

    标签: angular angular-material2


    【解决方案1】:

    向md-card 添加一个类,如下所示:

    .center{
      width: 75%;
      margin: 10px auto;
    }
    
    .main-div{
      height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    

    html:

    <div class="main-div">
      <md-card class="z-depth center" flex="50" >Simple card</md-card>
    </div>
    

    demo

    【讨论】:

    • 水平和垂直居中
    猜你喜欢
    • 2019-03-18
    • 1970-01-01
    • 2016-07-22
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    相关资源
    最近更新 更多