Centering with CSS Grid
suggest changeGrid can center an item on both axes without table-layout emulation:
<div class="stage">
<div class="item">Centered</div>
</div>
.stage {
min-block-size: 12rem;
display: grid;
place-items: center;
}
place-items: center is shorthand for align-items: center and justify-items: center. Use min-block-size instead of a fixed height when the container should be able to grow with its content.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents