简体   繁体   English

IE7浮动正确的错误?

[英]Ie7 float right bug?

I have a div floated right. 我有一个右浮动的div。 Inside that div are two other divs. 在该div内还有另外两个div。 The first div has a background color and when I refresh, it's "bleeding" into the second div. 第一个div具有背景颜色,当我刷新时,它会“渗出”到第二个div中。 (Sometimes in front of it sometimes behind it.) When I scroll, it fixes itself. (有时在它前面有时在它后面。)当我滚动时,它会自行修复。 When I refresh it does it again. 当我刷新时,它会再次执行。 This is only happening in IE7. 这仅在IE7中发生。 Bug? 错误? code below 下面的代码

#sidebar {float:right;width:310px;}
#articleSidebar {background:#DEE7E7;margin:0 5px 20px 5px;position:relative;}
#articleSidebarHeader {margin-top:10px;padding:5px;}
#articleSidebar h2, #articleSidebarHeader h2 {color:#5A5A5A;font-size:14px;font-weight:bold;}
#articleSidebar ul {color:#5A5A5A;font-size:11px;padding:0 7px;}
#articleSidebar ul li {background: transparent url(../images/bulletSquare9C.png) no-repeat scroll left 6px; padding:0 0 10px 7px;}
#articleSidebar ul li a {color:#5A6B73;display:block;text-decoration:underline;}
#articleSidebar ul li a strong {font-weight:bold;}
#sidebarAd {margin:0 5px 20px 5px;position:relative;}





<div id="sidebar">
        <div id="articleSidebar">
            <div id="articleSidebarHeader">
                <h2>Title here TBD</h2>
            </div>
            <ul>
                <li><a href="replaceMe">link</a>text</li>
                <li><a href="replaceMe">link</a>text</li>
                <li><a href="replaceMe">link</a>text</li>
                <li><a href="replaceMe">link</a>text</li>
            </ul>
        </div>
        <div id="sidebarAd">
        <!--300x250 ad here-->
        <iframe src="http://www.google.com" height="250" width="300" scrolling="no" frameborder="0"></iframe>
        </div>
    </div>

在IE6和7中,我通常使用position:staticzoom:1来解决问题。

I think you're relative positioning is part of the problem. 我认为您的相对定位是问题的一部分。 Both DIVs have the same relative positioning. 两个DIV具有相同的相对位置。 I think maybe in IE7 the position and height/width of the elements original position before applying the "relative" positioning is not calculated correctly. 我认为也许在IE7中,在应用“相对”定位之前,元素原始位置的位置和高度/宽度没有正确计算。

The fixes that come to mind are: 想到的解决方法是:

  1. Use absolute positioning. 使用绝对定位。 This takes the elements out of the DOM before repositioning, while not holding the space they would have occupied in the page. 这样可以在重新定位之前将元素从DOM中移出,同时不保留它们在页面中将占据的空间。 In this case the positioning values cannot be the same or they will overlay each other. 在这种情况下,定位值不能相同或彼此重叠。

  2. Preferred method Use "floated" divs to achieve the same effect of what it sounds like you are doing. 首选方法使用“ floated” div可以达到听起来像您正在做的效果。 Rather than the relative positioning, you can specify margin CSS definitions to achieve the same visual layout. 您可以指定边距CSS定义来实现相同的视觉布局,而不是相对定位。

     #articleSidebar {background:#DEE7E7;float:left;margin:0 5px 20px 5px;} #sidebarAd{margin:0 5px 20px 5px;float:left;} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM