-2

Only getting around to trying out flexbox now and I'm using it to vertically center content inside a div.

    .parent{
       display: flex;
       align-items: center;
       justify-content: center;
    }
    <div class="parent">
       <h1>Title</h1>
       <p>Paragraph one.</p>
       <p>Paragraph two.</p>
    </div>

So when I do this it works but the child elements are placed beside each other like they're not block items anymore. How can I have it that they're vertically centered but stacked on top of each other?

Cheers!

Amine KOUIS
  • 1,686
  • 11
  • 12
BarryWalsh
  • 1,300
  • 4
  • 14
  • 36

1 Answers1

1

If you want to show elements in column you need to use flex-direction: column style property.

.parent{
   display: flex;
   flex-direction: column;
   align-items: center;
   justify-content: center;
}
<div class="parent">
   <h1>Title</h1>
   <p>Paragraph one.</p>
   <p>Paragraph two.</p>
</div>
Andrew Kovalchuk
  • 897
  • 1
  • 10
  • 29