第1次尝试div+css进行两栏式页面布局就遇到了IE的3px问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
    *{
 margin:0px;
 padding:0px;
 }
    #top-right {
 /*margin-right:-3px;*/
 width:60px;
 height:30px;
 border:20px solid #f3c3f3;
 padding:40px;
 background-color:#eee;
 float:left;
 }
    #top-left {
 width:60px;
 height:30px;
 border:20px solid #f3c3f3;
 padding:40px;
 background-color:#eee;
 }
    #content {
 width:120px;
 border:40px solid #f3c3f3;
 padding:80px;
 }
</style>
</head>
<body>
<div id="top-right">aaa</div>
<div id="top-left">aaa</div>
<div id="content">bbb</div>
</body>
</html> 

用IE浏览器打开上面的网页文档,发现上面的左右两个div块并没有紧密相邻,而是中间有个3px的缝隙,去掉css中的那条注释语句,问题就解决了。

在css中加上如下的语句 :
body {
 width:360px;
 margin:0px auto;
 }

可以实现两栏的自动居中,且不受浏览器改变大小的影响。

posted on 2007-10-07 23:06  阳光VIP1  阅读(138)  评论(0编辑  收藏  举报