html - 如何在 IE7 中将绝对定位的 div 居中?

标签 html css internet-explorer layout internet-explorer-7

更新了布局的上下文

我的页面结构相对简单。该页面由两个绝对定位的 div 组成。一个以另一个为中心。 enter image description here

<div id="protocol_index_body_wrapper">
    <div id="protocol_index_body">
    </div>
</div>

里面有对应的CSS:

#protocol_index_body_wrapper {
    background: url("/images/stripe.png") repeat scroll 0 0 transparent;
    position: absolute;
    top: 120px;
    left: 0px;
    right: 0px;
    bottom: 10px;
}
#protocol_index_body {
    width: 960px;
    margin: 0 auto;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;

}

预期的行为如上图所示。此行为存在于 IE8、Firefox 和 Chrome 中。但是,在 IE7 中,应该居中的 div 与左侧齐平。有什么想法吗?

最佳答案

试试这个:

#protocol_index_body {
    width: 50px;
    margin: 0 auto 0 -25px;
    position: absolute;
    top: 0;
    left: 50%;
    right: 0;
    bottom: 0;
    background-color: red;
}

或者……

#protocol_index_body {
    width: 50px;
    margin: 0 auto 0 50%;
    position: absolute;
    top: 0;
    left: -25px;
    right: 0;
    bottom: 0;
    background-color: red;
}

关于html - 如何在 IE7 中将绝对定位的 div 居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8218582/

相关文章:

javascript - 根据选择选项使用 jquery 更新或替换 URL 参数

java - 如何将隐藏字段值从html页面传递到GWT页面?不同应用程序中的两个页面

html - 样式 ="display: none"不工作

css - 需要在 WooCommerce 结帐页面上隐藏一种付款方式

html - 简化 LESS 混音和参数

html - 独立于 <select> 调整 <option> 的大小

html - IE10 - RTL 反转 - 如何修复?

.net - 循环浏览 IE 8 中的所有选项卡

internet-explorer - IE9 的 jQuery "Exception thrown and not caught"问题

html - 使用 Bootstrap 将 span 放置在 div 下