I figured out a lot of these ways on my own. It's great to have a reference on how centering works. Instead of using translateX and translateY, just use translate(x, y) to minimize on code.
Also, I don't think you will need to set top, left, bottom, and right to zero in one of your examples. Just maybe set top, and left to zero and that should be enough.
Thanks for writing this useful article! I will use this sometime soon!
A front-end developer from Mar del Plata, Argentina. Passionate about CSS, accessibility, and JS. Currently working on "just a small fix", as I've been doing for the last 15 years.
Last time I counted, I found 13 different ways :) But most are variations or weird hacks that we don't really need anymore, so the three you posted should get us covered 99% of the time
I'm Calin Baenen – AKA KattyTheEnby – a programmer born October 30th, 2006.
I love programming, it has been my passion since I was a kid, and will forever be my passion.
Hello, world! I'm a professional self taught full-stack developer from Moscow. I truly love web-development and all that it concerns. Making websites is awesome. Follow me if you need some help
I figured out a lot of these ways on my own. It's great to have a reference on how centering works. Instead of using
translateXandtranslateY, just usetranslate(x, y)to minimize on code.Also, I don't think you will need to set
top,left,bottom, andrightto zero in one of your examples. Just maybe settop, andleftto zero and that should be enough.Thanks for writing this useful article! I will use this sometime soon!
Last time I counted, I found 13 different ways :) But most are variations or weird hacks that we don't really need anymore, so the three you posted should get us covered 99% of the time
Good, thank you very much
more of this series please
Must know things for beginners
Yes, you forgot the (deprecated, but still working)
<center>tag.This is an eternal problem. Thank you very much!
This is awesome!
From old times
parent
display: table
vertical-align: middle
text-align:center;
Child
display: inline-block
There's one more way by adding margin auto and line-height 100%
Great @katherinecode. I just learnt something new.