I am having difficulty trying to horizontally center an (inline?) element within my containing div. I want “some text” to have a background which collapses to it, and for that all to be centered within the containing element. I know I can do this if i specify a width, but I am trying to avoid that
Check out a simple example I put together with some nonworking css…
JSfiddle: http://jsfiddle.net/Mqw5R/ (works great even without js!)
<div>
<p>Some text</p>
</div>
=========================
= =
= |some text| =
= =
=========================
Add
text-align:centerto the containing element, not the child, like so:http://jsfiddle.net/thomas4g/Mqw5R/1/