1

As I understood from the documentation the justify-items would center it on the main axis and align-items would center it on the cross axis. So why is it, that the center-box is only aligned on the cross-axis (now vertical)?

By changing to flex-direction: column; it will horizontally align, but again the main axis seems to get ignored and so it will not center vertically in this case.

.flex 
{
  display: flex;
  justify-items: center; /* Does not seem to work */
  align-items: center;
}

.center-box
{
  background: green;
}

/* Flavor */
.flex 
{
  margin: 0 auto;
  width: 200px;
  height: 200px;
  background: red;
}
<div class="flex">
  <div class="center-box">Center Box</div>
</div>
Mark
  • 16,906
  • 20
  • 84
  • 117

2 Answers2

2

its justify-content:center; not justify-items:center;

Shafayet
  • 163
  • 7
0

.flex 
{
  display: flex;
  justify-content: center; 
  align-items: center;
}

.center-box
{
  background: green;
}

/* Flavor */
.flex 
{
  margin: 0 auto;
  width: 200px;
  height: 200px;
  background: red;
}
<div class="flex">
  <div class="center-box">Center Box</div>
</div>
fatm
  • 422
  • 2
  • 11