The critical piece I'm always missing is how to center a div vertically if you don't know its height?
The complete guide to centering a div
11–20 of 170 posts
Re: The complete guide to centering a div
#12I'm centered!
Re: The complete guide to centering a div
#13Re: The complete guide to centering a div
#14I'm centered!
Re: The complete guide to centering a div
#15The code in this section is incorrect. "margin: auto" does nothing in the vertical direction. If you set the height of the outer div to something more than 160 px, you will see that the inner div is not centered.
Re: The complete guide to centering a div
#16Re: The complete guide to centering a div
#17What about cases in which developer wants to vertically center a div, but he or she doesn't want to specify a height property?
Re: The complete guide to centering a div
#18The critical piece I'm always missing is how to center a div vertically if you don't know its height?
Re: The complete guide to centering a div
#19This is a pointless post. Use the TABLE tag. Yes, it will violate the purity of CSS, but you can trust it, and it will make your day better because it will free you angst and from extensive cross-browser testing. Simple is better than complex. Straightforward is better than arcane.
Using display: table-cell on a div is a more semantic approach than using .
Re: The complete guide to centering a div
#20The critical piece I'm always missing is how to center a div vertically if you don't know its height?
I found this a few days ago, I haven't tried it yet but it looks promising. http://snippetrepo.com/snippets/vertical-align-anything-with...
http://codepen.io/cheapsteak/pen/axJit
Doesn't work, unless you change `position: relative` to `position: absolute`