Replacing the Ghost-element Centering Hack

suggest change

The 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents