在浮动的div css下的margin-top

pav*_*los 6 css margin

我在浮动下有一个div:右边div.由于某种原因,上边距不能应用于第一个div.这是css

#over{
  width:80%;
  float:right;
  color:#e68200; 
 }

#under{
  clear:both;
  background:url(../images/anazitisi.png) no-repeat;  
  margin:10px auto; /*does not work!!!*/
  width:95px;
  height:20px;
 } 
Run Code Online (Sandbox Code Playgroud)

有谁知道发生了什么?

the*_*jon 8

漂浮的东西有点漂浮在正常的布局之外,因此通常不会影响其他没有漂浮的东西.当然,不同浏览器中的浮动行为有所不同,但这是一般的想法.

在浮动的div之后你需要一些东西(比如一个空的div)来清除浮动(有style ="clear:both;").

但是,就像我说的那样,浏览器的行为仍然会有所不同,然后决定应该从哪个数据开始计算.当然有解决方法.有关详细信息,请参阅此页面.