• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
PowerCoder
博客园    首页    新随笔    联系   管理    订阅  订阅

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="width:600px;height:300px;background-color:Black;float:left;"></div>
<div style="width: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;width: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="width:600px;height:300px;background-color:Black;float:left;"></div>
<div style="width: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;width:10px;"><!--在IE8下浮动元素对table会占位,由此更佳说明在IE8和
FireFox下浮动元素只对div来说不占位
--> 
<tr>
<td>
</td>
</tr>
</table>
<span style="clear:both;"><!--在IE8下非块级元素不可以清除浮动-->
456
</span>
<p 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; width:60px; height:60px; float:left;">

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

</td>
</tr>
</table>
第二行
</body>
</html>
posted @ 2009-09-04 18:05  PowerCoder  阅读(2137)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3