CSS makes simple things hard, and hard things impossible. This website is a tribute to everyone who has ever mass-deleted a stylesheet and started over.
CSS stands for Cascading Style Sheets. The "cascading" part means that when something breaks, everything below it breaks too. It was invented in 1996 and developers have been centering divs ever since.
As long as that browser is the one you tested it in. Results may vary in all other browsers, devices, screen sizes, and time zones.
After just 30 years, the CSS community has narrowed it down to only 12 different ways to vertically center an element. Most of them even work.
A beautiful system where the style you wrote last applies first, unless it doesn't, in which case you add !important and pray.