I have an outer div that is 800px wide. I have an inner div that could be anywhere from 200 to 600px wide.
I know how to center the inner div within the outer one if I set the inner one to have a specific width, but how do I center it since its a variable width?
Is there a way to set the div to only be the width of the elements inside of it, rather than having it expand to fill its containing div?
Floating, display:inline-block, or absolute positioning will shrink-wrap a div. Of those, display:inline-block would be the easiest to center with a simple text-align:center. If you have to support crappy browsers (I’m sure you do), check this out.
Assuming you aren’t supporting FF2 still, you can actually do away with most of the hacks, and still support older IE’s by making the inner div a span instead. display:inline-block works on older IE as long as the element was originally an inline element.