日期:2014-05-17  浏览次数:20581 次

为什么ie下margin-right会比原来多一倍?
<!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>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 无标题文档 </title>
<style   type= "text/css ">
#sub_div{
background-color:#6699FF;
width:873px;
height:540px;
margin:0   auto;
}
#login{
width:278px;
height:152px;
float:right;
margin-top:181px;
margin-right:35px;
text-align:left;
background-color:#999999;
}
html> body   #login{
margin-right:70px;
}
</style>
</head>

<body   leftmargin= "0 "   topmargin= "0 ">
<div   id= "sub_div ">
      <div   id= "login ">
      </div>
</div>
</body>
</html>


为什么ie下login   的margin-right会是70(原35的两倍)
而margin-top就正常181?firefox也正常
firefox正常ie不正常可以解释为浏览器对标准支持不一样,所以用html> body   #login{
margin-right:70px;
}来重新定义标准情况下的显示
可是为什么同一个浏览器margin-top   和margin-right却解释不一样呢?

------解决方案--------------------
IE6的双倍边距BUG,浮动后本来外边距35px,但IE解释为70px,解决办法是加上display:inline

------解决方案--------------------
你把开头的那些代码去掉就可以了 <!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 ">
------解决方案--------------------
恩,尽量避免这种双倍bug出现,用display:inline可以解决,但是总觉得这种hack该少用