简体   繁体   English

IE7错误-浮动:浮动的左子级:右父级

[英]IE7 Bug - float: left child of float: right parent

I'm having a weird issue (ie7 only) where the left floated child of a right floated element is not being constrained to its parent's width and is instead going all the way to the far left of the parent's parent and stopping at the closest left floated div. 我有一个奇怪的问题(仅适用于ie7),其中右浮动元素的左浮动子元素未受其父元素的宽度限制,而是一直沿父元素的父元素的最左端停在最左边浮动股 You can refer to the following fiddle for example code. 您可以参考以下小提琴以获得示例代码。 Looks fine in all other browsers, but unfortunately I have to support ie7. 在所有其他浏览器上看起来都不错,但是不幸的是我必须支持ie7。

Is there a way to fix this without setting an explicit width on the parent of the two floated sub-items and without changing the markup structure? 有没有一种方法可以解决此问题,而无需在两个浮动子项的父项上设置显式宽度,也无需更改标记结构?

http://jsfiddle.net/s89XZ/ http://jsfiddle.net/s89XZ/

Code from the fiddle attached below: 小提琴的代码如下:

    <style>
        .wrapper{
            position: relative;
            width: 500px;
            min-height: 18px;
            margin: 0 auto;
            padding: 14px 0;
            background-color: red;
        }
        .menu_L{
            color: #504A43;
            height: 18px;
            float: left;
            width: 100px;
            background-color: blue;
        }
        .menu_R_wrapper{
            float: right;
        }
        .menu_R{
            position: relative;
            float: right;
        }
        .menu_R .item_L,
        .menu_R .item_R{
            width: 50px;
            height: 18px;
        }
        .menu_R .item_L{
            float: left;
            background-color: orange;
        }
        .menu_R .item_R{
            float: right;
            background-color: green;
        }
    </style>
    <div class="wrapper">
        <div class="menu_L"></div>
        <div class="menu_R_wrapper">
            <div class="menu_R">
                <div class="item_L"></div>
                <div class="item_R"></div>
            </div>
        </div>
    </div>

You've to set width of floating parent in those lesser IE: please see http://jsfiddle.net/s89XZ/1/ where this width was added (it should be 100px here but 105px is better at showing that it works): 您必须在那些较小的IE中设置浮动父元素的宽度:请参阅http://jsfiddle.net/s89XZ/1/ ,其中添加了此宽度(此处应为100px,但105px更好地表明它可以工作):

.menu_R {
    width: 105px;
}

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

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