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

Q: 嵌套div的下移问题,可有正规的解决办法?

我在IE9上测试下面的代码,结果本该“置顶”的红色区域向下偏移了65个象素。

HTML code

<!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>
<title></title>
</head>
<body>  
      <div style="background-color:Red; height:100px;">
          <div style="margin-top:65px;">
              This is a string.
          </div>
      </div>
</body>
</html>



已知:
  1. 在第1个div中加入border-top: solid 1px Olive; 可以解决。
  2. 在2个div中间加入一个&nbsp 也可以解决。
  3. 在第2个div中加入float:left; 也可以解决。

请问有没有更好的方法,或者说传统的方法?感觉上面说的3个方法都有些山寨啊!

先谢谢大家了~~ :D

------解决方案--------------------
margin-top:65px;那要这个干嘛,删掉就行了
------解决方案--------------------
还是直接上你的代码吧
------解决方案--------------------
margin-top换成padding-top
------解决方案--------------------
连续两个嵌套DIV中间没有其它元素,内层的DIV的MARGIN会应用到外层上
------解决方案--------------------
style="margin-top:65px;"

朋友你加这行是为了什么?
删除即可。