The problem
You need to center content perfectly in both directions within a container.
The solution
.flex-center {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh; /* or any height */
}See it live
Put it to work
<div class="flex-center">
<div class="centered-content">
<h1>Perfectly Centered</h1>
<p>This content is centered both ways!</p>
</div>
</div>Worth knowing
This is the most reliable method for centering. Works with any content size.