Centering a Div with Flexbox
Flexbox makes it simple to center a div horizontally and vertically by aligning items along both the main and cross axes.
Set the parent container's display to flex.
Use justify-content: center to center items along the main axis (horizontal by default).
Use align-items: center to center items along the cross axis (vertical by default).
In this example, the .box div is perfectly centered both horizontally and vertically within the .container using Flexbox properties.
0-2 years experience
Optionally, use height on the container to ensure vertical centering works if the container has limited height.
5-8 years experience
8+ years experience