News for hackers. Stuff that matters.
Re:Solved by Flexbox by thekillingjoke on Friday May 22, 2015 @12:50PM (#9589499)
I think OP's point was that the trick to vertical centering involves wrapping a div as a table cell and then vertically aligning that. It should be much simpler, like 'text-align:center'
Re:Solved by Flexbox by pcwalton on Friday May 22, 2015 @01:49PM (#9589861)
Use margin: auto and absolute positioning to center something vertically. No tables or special magic needed.

I think "margin: auto" maybe should have been written "margin: center" to make it more obvious, but the feature is there.

Re:Solved by Flexbox by vukers on Friday May 22, 2015 @03:00PM (#9590291)
Absolute centering only works when the element you are trying to center has a defined height. If you are trying to center an element with unknown height inside a container with unknown height, the table-cell is likely the front-runner, sadly.
Re:Solved by Flexbox by pcwalton on Friday May 22, 2015 @03:06PM (#9590322)
I like the translateY(-50%) trick. But yeah, it is a pain point. Hence flexbox.
Re:Solved by Flexbox by Touche on Friday May 22, 2015 @10:14PM (#9591750)
People always suggest margin auto but at least for me having defined heights for elements is the very rare exception.
Re:Solved by Flexbox by xorcist on Friday May 22, 2015 @01:43PM (#9589830)
Why would you want to do that? That sounds absolutely horrific.

Just center the div in absolute mode. You need to have it wrapped in something though, to have something to center against, but you shouldn't have tables in there unless you want them.

Re:Solved by Flexbox by ConfuciusSay on Friday May 22, 2015 @04:10PM (#9590669)
The point remains that centering vertically with absolute positioning does not work with an element of variable height. Meanwhile, horizontally centering something of variable width is dead simple. Why the difference? It's a shortcoming of CSS.
Re:Solved by Flexbox by pcwalton on Friday May 22, 2015 @04:30PM (#9590767)
There is a fundamental reason for the difference: in standard CSS block/inline layout, widths depend on parent widths, but heights depend on child heights. Far from being stupid, this difference is the entire reason CSS is parallelizable at all.

Flexbox makes this simpler by switching to an entirely different model, which is the right approach for UIs (as opposed to documents). But I can't really fault CSS 2.1 for not introducing flexbox right away, because CSS 2.1 is complex enough as it is.

Re:Solved by Flexbox by marvy on Friday May 22, 2015 @09:27PM (#9591656)
Are UIs and documents so different?