简体   繁体   English

CSS浮动和iexplorer

[英]css floating and iexplorer

i have two divs, that float correctly in chrome, ff and safari but not iexplorer, the right div appears below the left div floated to the right- the two divs are wrapped by an outer div with a width of 800px; 我有两个div,它们分别在chrome,ff和safari中正确浮动,但不是iexplorer,右div出现在向右浮动的左div下面-两个div被宽度为800px的外部div包裹;

<div class="b_left">

</div>

<div class="b_right">

</div>

.b_left{
        width:350px;
        margin-left:80px;
        float:left;
        display: block;
    }

    .b_right{
        float:right;
        width:350px;
        height:280px;
        background-color:#c8c8c8;
        display: block;

    }

when using divs for columns, which I assume is what you are intending for this, it is better to only float one of the divs. 当我将div用于列时(我假设这是您打算这样做的),最好只浮动其中一个div。

Say i have a div called content which is 600px wide and inside it two 300px divs inside, leftblock and rightblock. 假设我有一个称为content的div,该div的宽度为600px,其内部为leftblock和rightblock两个300px div。 Instead of floating leftblock left and rightblock right I instead float the leftblock left and put a 300px margin-left on the rightblock. 我不是将左块向左浮动,而是将右块向右浮动,而是将左块向左浮动,并在右块上放置300px的空白边距。 This pushes the rightblock to the right and ensures room for the leftblock to fit in beside it while preventing IE from displaying weirdly. 这会将右图块推向右侧,并确保左图块适合在其旁边放置的空间,同时防止IE奇怪地显示。

Hope this helps 希望这可以帮助

I created a quick jsFiddle here: http://jsfiddle.net/6JWq9/ 我在这里创建了一个快速的jsFiddle: http : //jsfiddle.net/6JWq9/

And it shows up just fine. 它显示得很好。 I suspect you have other code that adds padding or a margin. 我怀疑您还有其他添加填充或边距的代码。 Review my example, let me know what is different from yours and I can update my answer. 查看我的示例,让我知道与您有什么不同,我可以更新答案。

it is a bug of ie, it doubles the margins. 这是一个错误,即它使利润增加了一倍。 you must add display inline to the .b_left. 您必须向.b_left添加内联显示。

display: inline

Just put margin: 0; 只需输入保证金:0; padding: 0; 填充:0; on all three divs and go from there to check. 在所有三个div上,然后从那里进行检查。 Also reset styles are a MUST for IE, I use Eric Meyer's. 对于IE,重置样式也是必须的,我使用的是Eric Meyer。 (easy to Google). (对Google来说很容易)。

Also, display: inline; 另外,显示:inline; on the one with margin will fix it for IE6 I suspect. 我猜想在保证金上会修复它。

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

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