how to center an inline div using css?

Mihai Om picture Mihai Om · Sep 6, 2010 · Viewed 81.7k times · Source

How can I center an inline div (not its content) using css?

VERY IMPORTANT: the width of the div is unknown (I can not specify it)

Answer

Moin Zaman picture Moin Zaman · Sep 6, 2010

If by inline you mean, its CSS display property is set to inline then you can center it by giving the immediate parent container a text-align:center

If you mean a div within another div, you can follow this approach if you can add a wrapper and float both:

How to horizontally center a floating element of a variable width?