since the way we center a div in a page is usually fix a width: 600px
and then set margin left and right both "auto"...
so what if we don't know the width in advance, or want it to be
automatic? in that case, use display: table? (as someone suggested
using that will make a div "shrink to fit". is it a standard way?
coz setting a non-table div to table display is kind of weird. any
other way?
Ben C - 30 Oct 2007 09:13 GMT
> since the way we center a div in a page is usually fix a width: 600px
> and then set margin left and right both "auto"...
Correct.
> so what if we don't know the width in advance, or want it to be
> automatic? in that case, use display: table? (as someone suggested
> using that will make a div "shrink to fit". is it a standard way?
> coz setting a non-table div to table display is kind of weird.
What's weird about it?
> any other way?
Display: inline-block with text-align: center on the container. But only
works in Opera and Konqueror/Safari out of well-known browsers.