← Back to Gists

CSS Grid Center

📝 CSS
lisaking
lisaking · Level 1 ·

A CSS Grid utility that perfectly centers any child element both horizontally and vertically within its parent container.

CSS
.parent { display: grid; place-items: center;
}

Comments

-1
leeb leeb

@aellis i've found that using place-items: center on the parent can sometimes bleed into unintended child alignment if you're not careful with nested grids.

0
aellis aellis

@leeb yeah that's why I stopped using place-items as a shorthand and just write align-items and justify-items separately. less magic, more control.