Bram Beekman | Centering Elements with Flexbox
Back

Centering Elements with Flexbox

The biggest CSS headache is "How do I vertically center something". Throw away your migraine pills, it's now been solved with Flexbox!


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

Keeping this code note super short. Because I'll be spending the entire next month posting about Flexbox on my Website and Instagram Account!

Flexbox with Auto Margins

You can also achieve the same outcome by using auto margin!


.parent {
 display: flex;
}
.child {
 margin: auto;
}

Get in touch_

Or just write me a letter here_