我有一个带有滚动内容的灯箱样式 div,我试图将其限制在视口内的合理大小。我也希望这个 div 水平居中。这在 Fx/Chrome/IE9 中都很容易。
我的问题是 IE8 忽略了我用来调整内容大小的绝对定位,以及margin: 0 auto
我用来水平居中灯箱的规则。
- 为什么?
- 我有哪些解决方法?
编辑:通过设置text-align:center
父元素来解决居中问题,但我不知道为什么会这样,因为我想要居中的元素不是内联的。仍然坚持绝对定位的东西。
HTML:
<div class="bg">
<div class="a">
<div class="aa">titlebar</div>
<div class="b">
<!-- many lines of content here -->
</div>
</div>
</div>
CSS:
body { overflow: hidden; height: 100%; margin: 0; padding: 0; }
/* IE8 needs ruleset above */
.bg {
background: #333;
position: fixed;
top: 0; right: 0; bottom: 0; left: 0;
height: 100%; /* needed in IE8 or the bg will only be as tall as the lightbox */
}
.a {
background: #eee; border: 3px solid #000;
height: 80%; max-height: 800px; min-height: 200px;
margin: 0 auto;
position: relative;
width: 80%; min-width: 200px; max-width: 800px;
}
.aa {
background: lightblue;
height: 28px; line-height: 28px;
text-align: center;
}
.b {
background: coral;
overflow: auto;
padding: 20px;
position: absolute;
top: 30px; right: 0; bottom: 0; left: 0;
}
这是问题的演示:http: //jsbin.com/urikoj/1/edit