IE7与FireFox、IE8下CSS浮动对比

IE7:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd"
>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title></title>
</head>
<body>
<div style="600px;height:300px;background-color:Black;float:left;"></div>
<div style="600px;height:300px;background-color:Yellow;float:right;"></div>
<div style="background-color:Green;height:100px;">aa</div><!--在IE7下div并不会被隐藏到浮动元素的下方,说
明浮动元素对于div来说是占位的
-->
<table style="background-color:Red;height:10px;10px;"><!--在IE7下浮动元素对table会占位--> 
<tr>
<td>
</td>
</tr>
</table>
<span style="clear:both;"><!--在IE7下非块级元素可以清除浮动-->
456
</span>

</body>
</html>

FireFox/IE8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd"
>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title></title>
</head>
<body>
<div style="600px;height:300px;background-color:Black;float:left;"></div>
<div style="600px;height:300px;background-color:Yellow;float:right;"></div>
<div style="background-color:Green;height:100px;">aa</div><!--在IE8下div会被隐藏到浮动元素的下方,说明浮动元素对于
div来说是不占位的,但是aa被挤在了中间,说明浮动元素对div中的非块级元素是要占位的
-->
<table style="background-color:Red;height:10px;10px;"><!--在IE8下浮动元素对table会占位,由此更佳说明在IE8和
FireFox下浮动元素只对div来说不占位
--> 
<tr>
<td>
</td>
</tr>
</table>
<span style="clear:both;"><!--在IE8下非块级元素不可以清浮动-->
456
</span>
<style="clear:both;"><!--在IE8下块级元素可以清浮动-->
789
</p>
</body>
</html>


另外有几个需要注意的地方:
div的display:inline后会完全消失

在IE和FireFox下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd"
>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title></title>
</head>
<body>
<div  style="background-color:Maroon; 60px; height:60px; float:left;">

</div><!--浮动元素会对其紧接的块级元素减少部分块,例如table:t1是块级元素,div浮动后t1却在div的右边没有满满的占满一行只占满了div右边部分-->
<table id="t1" style="background-color:Green; 60px; height:60px;">
<tr>
<td>

</td>
</tr>
</table>
第二行
</body>
</html>
原文地址:https://www.cnblogs.com/OpenCoder/p/1560512.html