Centering without Known Dimensions
suggest changeGrid centers content without fixed dimensions or extra wrappers:
<div class="container">
<div class="content">You can put anything here.</div>
</div>
.container {
min-block-size: 100dvh;
display: grid;
place-items: center;
padding: 1rem;
}
.content {
max-inline-size: 40rem;
padding: 1.5rem;
}
If the content grows taller than the viewport, min-block-size lets the container expand instead of clipping it. place-items centers the grid item on both axes.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents