CSS - How can I center a div within a div?

Posted by Spines on Stack Overflow See other posts from Stack Overflow or by Spines
Published on 2010-03-24T04:41:17Z Indexed on 2010/03/24 4:43 UTC
Read the original article Hit count: 145

Filed under:

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?

© Stack Overflow or respective owner

Related posts about css