Replacing the Ghost-element Centering Hack
suggest changeThe former “ghost element” technique inserted a full-height ::before pseudo-element, used vertical-align, and compensated for inline whitespace. Grid expresses the same intent directly:
.block {
display: grid;
place-items: center;
min-block-size: 20rem;
}
.centered {
inline-size: min(calc(100% - 2rem), 30rem);
}
This version needs no generated content, font-size reset, negative margin, or white-space override.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents