使用 css 将灵活宽度的内容居中
我在尝试将包含的 div 中的(内联?)元素水平居中时遇到困难。我希望“某些文本”有一个折叠到它的背景,并且所有这些都在包含元素内居中。我知道如果我指定宽度我可以做到这一点,但我试图避免这种情况
查看我与一些非工作CSS放在一起的一个简单示例... JSfiddle: http://jsfiddle.net/Mqw5R/ (即使没有 js 也能很好地工作!)
<div>
<p>Some text</p>
</div>
=========================
= =
= |some text| =
= =
=========================
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| =
= =
=========================
http://jsfiddle.net/Mqw5R/3/
为什么不把
你 DIV CSS?
http://jsfiddle.net/Mqw5R/3/
Why don't you just put
Inside of your DIV css?