简体   繁体   English

ie7多个浮动div,其百分比宽度等于容器div内的100%

[英]ie7 multiple floating divs with percentage widths equaling 100% inside container div

This seems to works in ie8, Chrome, and Firefox. 这似乎适用于ie8,Chrome和Firefox。 Everything should be on the same line, but in ie7 the last div for some reason doesn't seem to "fit" and gets dropped down to the next line. 一切都应该在同一条线上,但在ie7中,由于某种原因,最后一个div似乎并不“适合”并且下降到下一行。 Is there a simple way to get this to work with ie7? 是否有一种简单的方法可以使用ie7?

<div style="width: 95%">

    <div style="width: 25%; background-color: blue; float: left;">test1</div>

    <div style="width: 25%;  background-color: green;float: left;">test2</div>

    <div style="width: 25%;  background-color: red;float: left;">test3</div>

    <div style="width: 25%;  background-color: yellow;float: left;">test4</div>

</div>

你可能不得不将它们设置为24.9%,因为IE的组合百分比宽度为100%。

You should just set clear:right; 你应该设置清楚:正确; for all your floating div elements. 对于所有浮动div元素。 It'll works fine for IE. 它适用于IE。

It's simple math! 这是简单的数学!

If your <div style="width: 95%"> is generating a 100px element, each childelement of 25% will result in elements of 25px. 如果<div style="width: 95%">生成一个100px元素,则每个25%的childelement将生成25px的元素。

However, if your <div style="width: 95%"> is generating a 150px element, each childelement will be 37.5px 但是,如果<div style="width: 95%">生成150px元素,则每个childelement将为37.5px

IE will then round this value up to 38px (because you can't have half a pixel). 然后IE会将此值四舍五入到38px(因为你不能有半个像素)。 You will then end up with 4 elements of 38px = 152px 然后,您将得到4个38px = 152px的元素

Hope this helps... 希望这可以帮助...

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

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