Live data from Hacker News

How to Center in CSS

howtocenterincss.com

1–10 of 297 posts

Re: How to Center in CSS

#6
This might need some updating. I did a quick run through and it recommended me to use a table-cell for vertical centering. You might be able to do that more easily with flexbox.

Re: How to Center in CSS

#7
I remember when I was first learning CSS and I found out this wasn't easy. I thought "oh my god, this learning to code stuff is gonna be HARD!"

A few years later and I don't think anything but the occasional third party api with undocumented behavior has been nearly as hard.

Re: How to Center in CSS

#9
This site doesn't seem to be suggesting absolute centering [1] when it would be the easiest way to center things.

"margin: auto" seems to be the way that the designers of CSS 2.1 intended to center things. 90% of the time, absolute centering is the easiest way to center in CSS; you should prefer it when possible.

[1]: http://codepen.io/shshaw/full/gEiDt

Re: How to Center in CSS

#10
Doesn't Flexbox pretty much solve this problem? I mean, if you need to maintain backwards compatibility this might be reasonable, but "justify-content: center" and "align-items: center" seem to work unreasonably well for this exact purpose.
Post reply on HN