float和margin-top

如果三个兄弟元素A,B,C按顺序包含在同一个元素下,A元素使用了float,则B元素不能够设置margin-top值,但可以设置margin-bottom和margin-left/right的值;C的四个margin值都可以设置;

 所以,如果你希望A和B之间又间距,其中一个办法是,在A和B之间添加一个div,将div的高度设置为希望两者相距的px值(此时B不需要再添加margin) 或者不设置div高度,直接设置B的Margin也行;

这个div(help)可以不添加内容,但是一定要设置width和height,哪怕设置为0;

<div  class="father">

  <div  class="A">  </div>

 <div   class="help"></div>

<div class="B"></div>

</div>

<style>

.A {   float:left;  }

.help {   width:100%;    height:20px;   }

<style>

猜你喜欢

转载自blog.csdn.net/kalinux/article/details/84192029