我正在尝试使用一种已知的方法使我的 DIV 在另一个 DIV 中水平居中,而不知道嵌套 DIV 上的内部 DIV 的宽度(缩小到内容方法)。
这是HTML:
<div class="my-container">
<div class="my-wrapper">
<div class="item">
<span>My Item</span>
</div>
</div>
</div>
这是CSS:
div.my-container {
width: 300px;
height: 100px;
padding: 100px 0 0 0;
border: 1px solid #000;
}
div.my-wrapper {
background-color: blue;
text-align: center;
}
div.item {
display: inline-block;
padding: 0 20px;
background-color: pink;
}
div.item span {
display: inline-block;
height: 50px;
background-color: red;
}
jsFiddle 上的测试用例:http: //jsfiddle.net/ThZxx/2/
在所有浏览器中看起来都很好:
除了 Internet Explorer 7:
看起来粉红色的 DIV (div.item)没有缩小到内容并占用父容器中的所有可用空间。
我怎样才能解决这个问题?