Html 绝对中心水平,负边缘,IE6

Html 绝对中心水平,负边缘,IE6,html,css,position,internet-explorer-6,css-position,Html,Css,Position,Internet Explorer 6,Css Position,在所有支持负边距的现代浏览器中,使用负边距将元素放在中间效果良好 但在IE6中,我们能做什么 例如,此代码在IE6中失败: HTML: <div id="parent"> <div id="child"></div> </div> #parent{ position: relative; width: 500px; height: 500px; margin: 25px auto; backgrou

在所有支持负边距的现代浏览器中,使用负边距将元素放在中间效果良好

但在IE6中,我们能做什么

例如,此代码在IE6中失败:

HTML:

<div id="parent">
    <div id="child"></div>
</div>
#parent{
    position: relative;
    width: 500px;
    height: 500px;
    margin: 25px auto;
    background: skyblue;
}

#child{
    position: absolute;
    width: 300px;
    height: 100px;
    left: 50%;
    margin-left: -150px;
    top: 25px;
    background: orange;
}

请参阅。

这可能不适用于您的特定场景,但您是否可以尝试使用边距和填充,而不是定位

#parent{
    width: 500px;
    height: 500px;
    margin: 25px auto;
    padding-top: 25px;
    background: skyblue;
}

#child{
    width: 300px;
    height: 100px;
    margin-left: auto;
    margin-right: auto;
    background: orange;
}

只是想知道,你为什么要浪费时间为IE6开发?这不是谷歌仍在主页上使用标签的原因吗?@boj:我知道,但我的客户想要它。他的网络中有一些IE6用户…:(@kikio我为你感到难过。@Louis:
对绝对位置元素有影响吗?