Float left in a div does not work in IE7 but does in Firefox and IE8

半城伤御伤魂 提交于 2019-12-05 20:20:11

You should almost always include an explicit width when you're floating elements.

If you don't, browsers have to guess what you mean. In this case, Firefox is guessing better than IE, but you shouldn't make them guess. Be explicit where you can.

edit: If you want all three boxes to expand with the content, I'd suggest setting percentage-based widths. In general, you're going to want to look up techniques for fluid column layouts.

Just discovered that if you have a float and a clear applied to a DIV IE7 chokes.

Instead, specify the float, in the DIV's CSS, but remove the clear and place an empty div, after the DIV in question, like this:

BEFORE:

<div style="float:left; clear:right;">Content goes here</div>

AFTER

<div style="float:left;">Content goes here</div>
<div style="clear:right;"></div>

Have you considered display:inline-block instead of floating? I don't think you can do what you want with floats AND support IE without using some JS to explicitly define width on each floated element.

Another note, you have to declare a second separate rule for block level elements in IE:

HTML:

<div class="foo">test</div><div class="foo">bar</div>

CSS:

.foo { display:inline-block; }
.foo { display:inline; } /* Feed this to IE below 9 only with a CC. Don't feed it to modern browsers */
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!