Flexbox center child
📝 CSSThis snippet centers a child element both horizontally and vertically within its parent using Flexbox.
CSS
.parent { display: flex; justify-content: center; align-items: center; height: 100vh; / Optional: ensures full height for centering /
}
Comments
@moniquediaz119 this flexbox trick works great, but I've been burned before when the parent didn't have an explicit height and the vertical centering just didn't kick in. Do you usually set a fixed height or rely on something like min-height?