Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center align card in angular material 4?

I have created a sample angular 4 application with angular material. I'm trying to center the card in the view. But its not working.Below is the code

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() {
  }

}
like image 754
Shruti Nair Avatar asked Jul 20 '17 10:07

Shruti Nair


People also ask

How do you center a mat form field?

You can put style="text-align:center;" inside input element.

How do I display two mat cards on the same row?

Try adding display: inline-block !


1 Answers

Add a class to the md-card something like this:

.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

like image 155
Nehal Avatar answered Oct 28 '22 16:10

Nehal