IE6和IE7下绝对定位position:absolute和margin的冲突问题解决
2016-11-29 00:00
591 查看
绝对定位的Position:absoulte的元素,会让相邻的兄弟元素的margin-top失效。而如果去掉了兄弟元素的高度又会正常。
效果图:
从运行的效果图可以看到在chrome下是没有问题的,在IE7下就出现了,我开头所说的问题,FF也是没有问题的!
BUG主要有以下两个:1、Layer2在IE7下相邻的兄弟结点即Layer3的margin-top没有用了,2、layer2 无法靠左,距离左边的距离为layer1的第一个非绝对定义元素(layer3)的margin-left值。
解决的方案有以下几种:
1、添加代码:添加代码:<!–[if lte IE 7]>
<[endif]–>,这也是网上找到的能够完全解决问题的方法。即代码变为:
2、外围元素加position:relative定义,绝对定义元素加left和top定义。此方法可以解决第二个bug,无法解决第一个bug。也有说法用padding-top替代margin-top的,但是有时可以这样,有时候毕竟不行的。
3、这是本文所要阐述的方法,相对来说比较完美一些。给绝对定义元素添加“background-color:#CCC; float:left; display:inline;”定义,背景色千万不可以去掉,如果没有背景色就加一个透明(background-color:transparent;)。即代码变为:
参考:
http://www.jb51.net/css/74238.html
<div id="layer1" style="margin:20px; border:1px solid #F88; width:400px; "> <div id="layer2" style="position:absolute; background-color:#ccc;">Absolute (layer2)</div> <div id="layer3" style="margin:30px auto; width:200px; height:80px; background-color:#36F;">Normal Text Content (layer3) </div>
效果图:
从运行的效果图可以看到在chrome下是没有问题的,在IE7下就出现了,我开头所说的问题,FF也是没有问题的!
BUG主要有以下两个:1、Layer2在IE7下相邻的兄弟结点即Layer3的margin-top没有用了,2、layer2 无法靠左,距离左边的距离为layer1的第一个非绝对定义元素(layer3)的margin-left值。
解决的方案有以下几种:
1、添加代码:添加代码:<!–[if lte IE 7]>
<[endif]–>,这也是网上找到的能够完全解决问题的方法。即代码变为:
<div style=”margin:20px; border:1px solid #F88; width:400px; “> <div style=”position:absolute; background-color:#ccc;”>Absolute (layer2)</div> <!–[if lte IE 7]><div></div><![endif]–> <div style=”margin:30px auto; width:200px; height:80px; background-color:#36F;”>Normal Text Content (layer3)</div> </div>
2、外围元素加position:relative定义,绝对定义元素加left和top定义。此方法可以解决第二个bug,无法解决第一个bug。也有说法用padding-top替代margin-top的,但是有时可以这样,有时候毕竟不行的。
<div style=”margin:20px; border:1px solid #F88; width:400px; position:relative”> <div style=”position:absolute; background-color:#ccc; left:0; top:0;”>Absolute (layer2)</div> <div style=”margin:30px auto; width:200px; height:80px; background-color:#36F;”>Normal Text Content (layer3)</div> </div>
3、这是本文所要阐述的方法,相对来说比较完美一些。给绝对定义元素添加“background-color:#CCC; float:left; display:inline;”定义,背景色千万不可以去掉,如果没有背景色就加一个透明(background-color:transparent;)。即代码变为:
<div style=”margin:20px; border:1px solid #F88; width:400px;”> <div style=”position:absolute; background-color:#ccc; float:left; display:inline;”>Absolute (layer2)</div> <div style=”margin:30px auto; width:200px; height:80px; background-color:#36F;”>Normal Text Content (layer3)</div> </div>
参考:
http://www.jb51.net/css/74238.html
相关文章推荐
- IE6和IE7下绝对定位position:absolute和margin的冲突问题解决
- IE6、IE7下绝对定位position:absolute和margin的冲突bug解决方法
- IE6/IE7下绝对定位position:absolute和margin的冲突问题解决
- IE6、IE7下绝对定位position:absolute和margin的冲突bug解决方法
- 解决IE6 下 position:fixed 绝对定位的问题
- 解决margin-bottom 在IE7、IE6下,失效问题
- IE6下position:absolute定位错误的bug和解决方法
- ie6使用绝对定位position:absolute,box不显示
- 解决 IE6 position:fixed 固定定位问题
- 解决 IE6 position:fixed 固定定位问题
- IE6、IE7、Firefox中margin问题解决办法
- 【转】IE7 position:absolute还是被盖住问题解决
- IE6 / IE7 / Firefox 的margin问题解决办法
- 解决IE6下 position的fixed定位问题
- 解决IE6浏览器下position:fixed固定定位问题
- IE6/IE7下position:absolute;绝对定位偏移、不显示问题
- IE6 / IE7 / Firefox 的margin问题解决办法
- 绝对定义(position:absolute)的相邻元素margin-top在IE6下失效
- 解决IE6浏览器下position:fixed固定定位问题