Funny/Humor

How to center a div in CSS with flexbox or grid

How to centre a div in CSS with flexbox or grid: justify-content, align-items and place-items explained, plus why vertical centring used to be so hard.

  • 3 min read
  • 3 questions
  • +25 XP
Transcript

Centering a div. Explained by cats. Kitty makes a website. Kitty adds an element, a div. She wants it perfectly centered. Quick pause to say Kitty is excited to partner with Microsoft developer. Back to centering the div. Kitty tries margin.

Wait, why is it sideways? Let's try position. Box runs away. Chaos, hissing, tail puffed? Kitty searches how to center a div. Finds 12 different answers. None work. Finally, Kitty meows to GitHub copilot. Center this div. Copilot does the magic. Kitty runs it. Perfectly centered. Now Kitty naps proudly on the keyboard.