Centering with Flexbox
suggest changeHTML:
<div class="container">
<div class="child"></div>
</div>
CSS:
.container {
height: 500px;
width: 500px;
display: flex; /* Use Flexbox */
align-items: center; /* Centers children on the block axis (vertically, in a row). */
justify-content: center; /* Centers children on the main axis (horizontally, in a row). */
background: white;
}
.child {
width: 100px;
height: 100px;
background: blue;
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents