About Flexbox

THE OLD WAY

Before flexbox you had to use floats and complicated math to layout a website. This was frustrating and never worked the way you wanted. This is because they way you want to use it is not the way it was designed to be used. Floats were only created to allow text to flow around images.

Vertical centering before flexbox was one of the most prevalent problems in web design. Many solutions involve fixed size containers, carefully calculated margins that could break at any moment, or the relatively simple solution below. All of these solutions however, involve too much work for such basic tasks.

.container{
position: relative;
}
.child{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

THE NEW WAY

Hacking and entire layout is obviously not ok, so the internet gods created flexbox. Flexbox was designed specifically to make coding layouts easier. Flexbox allows a container to adjust its child elements width, height, order, and spacing in all directions.

Vertical centering with flexbox is extremely simple thanks to its ability to automatically space elements in both horizontal and vertical directions.

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

Terminology

diagram

Flexbox is not without its faults

The Flexbox Sandbox