简体   繁体   English

IE7向右浮动错误-常规解决方案无效

[英]IE7 float right bug-no usual solutions work

I am beyond frustrated. 我无比沮丧。 I have been researching an answer to this for hours and to no avail. 我一直在研究这个问题的答案数小时,但无济于事。 Yes, I know there is already a discussion about this here: IE7 float right causes parent element to take up full width 是的,我知道这里已经有关于此的讨论: IE7右浮动会导致父元素占用全宽

but it doesn't seem to solve my issue. 但这似乎无法解决我的问题。 :( :(

I have 2 floats (a left and right) within a right floated element. 我在右浮动元素内有2个浮点数(左和右)。 Of course in every browser it works except IE7. 当然,除了IE7之外,在所有浏览器中都可以使用。 The parent right floated element stretches to full width instead of wrapping around the 2 floats within. 父右边的float元素会拉伸到完整宽度,而不是环绕其中的2个float。

I have tried zoom:1 on the parent element. 我在父元素上尝试过zoom:1。 I have tried display: inline-block on the parent element. 我试过在父元素上显示:inline-block。 I have tried min-width: 1px on the parent element. 我在父元素上尝试了min-width:1px。

NONE of which work! 没有任何工作! I have tried them altogether as well as separately and still no change in IE7. 我已经分别尝试了它们,并且在IE7中仍然没有任何变化。 What am I doing wrong??? 我究竟做错了什么???

<div class="parentfloat">
    <div class="leftblock">
        LEFT FLOAT 
    </div>
    <div class="rightblock">
        RIGHT FLOAT            
    </div>
</div>

.parentfloat {
    float: right;
    display: inline-block;
    zoom: 1;
    min-width: 1px;}

.leftblock {
    float: left; 
    text-align: left; 
    margin-right: 60px;
    padding: 0;}

.rightblock {
    float: right; 
    text-align: right; 
    padding: 0;}

By not setting an explicit width for the .parentfloat containing element, it is by default (in IE7) expanding to take up 100% of the width. 通过不为包含.parentfloat的元素设置显式宽度,默认情况下(在IE7中)它会扩展为占用宽度的100%。 The fix for this is defining an explicit width for your .parentfloat class. 解决此问题的方法是为.parentfloat类定义一个显式宽度。

See this jsfiddle for an example (I added background-colors for clarity). 请参阅此jsfiddle示例(我为清楚起见添加了背景颜色)。

EDIT: Considering this is an IE7 specific bug, I would recommend only apply the fixed width to IE7 either through the use of a conditional stylesheet, a css hack, or a conditional class . 编辑:考虑到这是特定于IE7的错误,我建议仅通过使用条件样式表,css hack或条件类将固定宽度应用于IE7。

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

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