Interview Question

How do you center elements vertically and horizontally?

Center children through Grid or Flexbox alignment on their parent.

💡 Concept ✅ Quick Revision 🎨 CSS

Answer

Center several child elements by applying alignment rules to their layout container. • Grid can center children with place-items. • Flexbox uses justify-content and align-items. • Keep source order logical because alignment changes presentation, not reading order.

💡 Simple Example

.container { min-height: 20rem; display: grid; place-items: center; }

⚡ Quick Revision

Center children through Grid or Flexbox alignment on their parent.