ie7中绝对位置问题,div向右移动10px [英] Problem with position absolute in ie7, div moves 10px to the right

查看:27
本文介绍了ie7中绝对位置问题,div向右移动10px的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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"><头><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">正文{边距:0 0 0 0;填充:0 0 0 0;}#holder{宽度:400px;高度:500px;边距:0 自动;}#left{浮动:左;宽度:50px;高度:500px;背景颜色:红色;}#center{浮动:左;宽度:300px;高度:500px;背景颜色:绿色;}#右{浮动:左;宽度:50px;高度:500px;背景颜色:红色;}#header{宽度:300px;高度:70px;背景颜色:黄色;}#gal-holder{宽度:280px;高度:70px;边距:0 自动;}#gallery{宽度:280px;高度:410px;背景颜色:橙色;}#button{width: 400px;高度:45px;背景颜色:红色;边距:0 自动;}#menu{宽度:300px;高度:45px;背景颜色:粉红色;位置:绝对;z-索引:1000;顶部:100 像素;}#content{width: 380px;高度:200px;边距:0 自动;背景颜色:蓝色;填充:10px;颜色:#fff;}#clear{高度:10px;}</风格><身体><div id="持有人"><div id="左"></div><div id="中心"><div id="header"></div><div id="菜单"></div><div id="gal-holder"><div id="清除"></div><div id="画廊"></div><div id="清除"></div>

<div id="right"></div>

<div id="按钮"></div><div id="content">示例文本</div>

解决方案

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

绝对定位的元素相对于它们最近定位的父元素进行定位.最好为您要定位的项目提供左/右和上/下坐标,以防止出现像您发现的那样的奇怪结果.

ive got a problem on my position absolute property on IE7. My div moves 10px to the right. Below is my code. IE8 and 9 works fine. id menu is the div Im referring.

<!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>

解决方案

Add position:relative to #center and then left:0px to #menu.

Absolutely positioned elements are positioned relative to their closest positioned parent. It's best to give the items you want to position a left/right and top/bottom coordinate to prevent weird results like the one you found.

这篇关于ie7中绝对位置问题,div向右移动10px的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆