The complete guide to centering a div
1–10 of 170 posts
Re: The complete guide to centering a div
#2Shame that demo's take you out of the site.
Re: The complete guide to centering a div
#3The 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
#4The critical piece I'm always missing is how to center a div vertically if you don't know its height?
Well, I'd use display:table-cell with vertical-align:middle.
Re: The complete guide to centering a div
#5This 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.
Re: The complete guide to centering a div
#6I'm centered!
Re: The complete guide to centering a div
#7This 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
#8I'm centered!
DRY, though, right? Changing one set of CSS rules is better than hunting down 20 elements when requirements change. Not to mention is deprecated.
Re: The complete guide to centering a div
#9I was wondering why the demo is not working for me. it really took me a while to realize that it is actually a button.
Re: The complete guide to centering a div
#10This 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.
As igvadaimon wrote below, there's no need for a tag. Instead of:
my div
you can do
my div
The inline styling is just for illustrative purposes, of course.