微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我在IE7上的位置绝对属性有问题.我的div向右移动了10px.以下是我的代码. IE8和9工作正常.
id菜单是我指的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>

解决方法

添加位置:相对于#center然后左:0px到#menu.

绝对定位的元素相对于其最接近的父母定位.最好给出你想要定位左/右和上/下坐标的项目,以防止像你找到的那样奇怪的结果.

原文地址:https://www.jb51.cc/css/216165.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。