Centering flexible width content with css
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 开发者_StackOverflowtext</p>
</div>
=========================
= =
= |some text| =
= =
=========================
http://jsfiddle.net/Mqw5R/3/
Why don't you just put
text-align:center;
Inside of your DIV css?
Add text-align:center
to the containing element, not the child, like so:
http://jsfiddle.net/thomas4g/Mqw5R/1/
精彩评论