css - ie7中绝对位置问题,div向右移动10px

标签 css position positioning absolute internet-explorer-7

我在 IE7 上的位置绝对属性上遇到了问题。我的 div 向右移动 10px。下面是我的代码。 IE8 和 9 工作正常。 id menu 是我指的 div。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body{margin: 0 0 0 0; padding: 0 0 0 0;}
#holder{width: 400px; height: 500px; margin: 0 auto;}
#left{float: left; width: 50px; height: 500px; background-color: red;}
#center{float: left; width: 300px; height: 500px; background-color: green;}
#right{float: left; width: 50px; height: 500px; background-color: red;}
#header{width: 300px; height: 70px; background-color: yellow;}
#gal-holder{width: 280px; height: 70px; margin: 0 auto;}
#gallery{width: 280px; height: 410px; background-color: orange;}
#button{width: 400px; height: 45px; background-color: red; margin: 0 auto;}
#menu{width: 300px; height: 45px; background-color: pink; position: absolute; z-index: 1000; top: 100px;}
#content{width: 380px; height: 200px; margin: 0 auto; background-color: blue; padding: 10px; color: #fff;}
#clear{height: 10px;}
</style>
</head>
<body>
<div id="holder">
    <div id="left"></div>
    <div id="center">
        <div id="header"></div>
        <div id="menu"></div>
        <div id="gal-holder">
            <div id="clear"></div>
            <div id="gallery"></div>
            <div id="clear"></div>
        </div>
    </div>
    <div id="right"></div>
</div>
<div id="button"></div>
<div id="content">Sample text</div>
</body>
</html>

最佳答案

position:relative添加到#center,然后将left:0px添加到#menu

绝对定位的元素相对于它们最近的定位父元素定位。最好为您要放置的元素提供左/右和上/下坐标,以防止出现像您找到的那样奇怪的结果。

关于css - ie7中绝对位置问题,div向右移动10px,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5100998/

相关文章:

javascript - 如何在将鼠标悬停在动态添加的缩略图上时添加样式?

javascript - 计算div在div中的位置

css - 页眉 Div 位置固定在页面顶部,但在加载时在其顶部显示一个 div

html - 在一行上,最左边两个元素,最右边一个元素,内容垂直居中,没有固定大小

javascript - 当不透明度为 0 时隐藏 div 中的可点击链接

css - 在 CSS Sprite 下对齐文本

html - 如何让文本溢出与表 <td> 标签一起使用

html - 如何将背景图片保留在页面底部?

Jquery 动画溢出元素在 Safari 中移动

android - 同一行上的多个按钮/对象