简体   繁体   English

ie7浮动右父母宽度问题

[英]ie7 float right parent width problems

This one is really getting my goat. 这真的让我很山羊。 I need to float Container1 and Container 2 to the right and have them butt up against each other as they are now. 我需要将Container1和Container 2浮动到右侧,并使它们彼此对接。 I also need to float items inside Container2 to the right so they stack on each other. 我还需要将Container2中的项目浮动到右侧,以便它们彼此堆叠。 Problem is if I set anything inside Container2 (sample text 2, sample text 3) to float right it makes Container2 width 100% or something. 问题是,如果我将Container2内的任何内容(示例文本2,示例文本3)设置为向右浮动,则会使Container2的宽度变为100%左右。

This could be solved by giving Container2 a specific width but that is not possible as all of this is dynamic content. 可以通过为Container2指定一个特定的宽度来解决此问题,但这是不可能的,因为所有这些都是动态内容。 I need Container2 to grow as i stack things inside it. 当我在其中堆叠东西时,我需要Container2才能成长。

Is there any way around this? 有没有办法解决? It is only a problem in ie7 all other browsers seem to be fine. 在ie7中,这只是一个问题,所有其他浏览器似乎都不错。 This is driving me mad. 这让我发疯。

<div>
    <div style="width: 100px; height: 100px; background: green; float: left;">
    </div>
    <div id="Container1" style="height: 100px; border: 1px solid #000000; float: right;">
        sample text 1
    </div>
    <div id="Container2" style="height: 100px; border: 1px solid #000000; float: right;">
        <div style="float: right; border: 1px solid #FF0000;">sample text 2</div>
        <div style="float: right; border: 1px solid #00FF00;">sample text 3</div>
    </div>
</div>

I couldn't find a fix to this bug in Internet Explorer 7. 我在Internet Explorer 7中找不到此错误的修复程序。

There might be one, I don't know. 可能有一个,我不知道。 I tried all the usual tricks. 我尝试了所有常用的技巧。

Here's some reworked code utilising display: inline-block . 这是一些利用display: inline-block重做的代码display: inline-block

It looks identical to your old code in IE8, and is consistent in IE7/8 and other modern browsers. 它看起来与IE8中的旧代码相同,并且在IE7 / 8和其他现代浏览器中保持一致。 Yay! 好极了!

See: http://jsfiddle.net/SUPhf/ 请参阅: http //jsfiddle.net/SUPhf/

There are a number of things to be aware of: 有很多事情要注意:

Now that you're aware of those caveats, this should be fine. 现在您已经意识到了这些警告,这应该没问题。

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

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