I want to center a div in the middle of my page, and have the div fit the contents. How can I do that?
I've tried
width: 1px;
white-space: nowrap;
margin: 0 auto;
Which centers the div, but then all the text is to the right of that.
display: inline-block
makes the div fit the contents, but then margin: 0 auto;
doesn't seem to work...
Does this work for you: http://vidasp.net/tinydemos/inline-centered-div.html
body { text-align:center; }
div { display:inline-block; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With