Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular material layout-align = "center center" not working

I'm trying to use the layout-align = "center center" which should align the content at center both vertically and horizontally. But it's only aligning the content horizontally and not vertically.

Here's the plnkr link of the code I'm trying.

<body ng-app="app" ng-controller="appCtrl">
<md-toolbar>
<div class="md-toolbar-tools">
  <h2 flex>Hello Angular-material!</h2>
</div>
</md-toolbar>
<div class="flexbox-parent">
  <div layout="row" layout-align="center center">
   <div flex="15">First line</div>
   <div flex="15">Second line</div>
  </div>
</div>
</body>
like image 479
Prabhdeep Avatar asked Nov 19 '15 21:11

Prabhdeep


3 Answers

The reason why it is not centering it vertically is because your div containing the layout-align attribute does not have a height.

Try something like

<div class="flexbox-parent">
  <div layout="row" layout-align="center center" style="min-height: 500px">
   <div flex="15">First line</div>
   <div flex="15">Second line</div>
  </div>
</div>
like image 193
Brady Liles Avatar answered Nov 15 '22 21:11

Brady Liles


Just use

fxLayout="row" fxLayoutAlign="center center" style="height: 100vh; width: 100vh"

on your parent div

like image 26
smedasn Avatar answered Nov 15 '22 21:11

smedasn


Flexbox vertical centering works well with defining height for the parent element:

<div class="flexbox-parent">
  <div layout="row" layout-align="center center"  style="height: 100vh">
   <div flex="15">First line</div>
   <div flex="15">Second line</div>
  </div>
</div>
like image 36
Nikhil Raj A Avatar answered Nov 15 '22 19:11

Nikhil Raj A