父元素div清除浮动的三种方式

第一种做法:

父元素也设置:浮动

<style>

  div.b{

    float:left;

  }

  div.c{

    float:left;

    width:250px;

    height:100px;

  }

  div.d{

    float:right;

    width:250px;

    height:100px;

  }

</style>

<div class="b">

  <div class="c"></div>

  <div class="d"></div>

</div>

 

第二种做法:在最后添加一个空标签

<style>

  div.c{

    float:left;

    width:250px;

    height:100px;

  }

  div.d{

    float:right;

    width:250px;

    height:100px;

  }

</style>

<div class="b">

  <div class="c"></div>

  <div class="d"></div>

  <div style="clear:both;"></div>

</div>

 

第三种做法:给父元素添加清楚浮动

<style>

  div.b:after{

    content:'.';

    display:block;

    height:0px;

    clear:both;

    visibility:hidden;

  }

  div.c{

    float:left;

    width:250px;

    height:100px;

  }

  div.d{

    float:right;

    width:250px;

    height:100px;

  }

</style>

<div class="b">

  <div class="c"></div>

  <div class="d"></div>

</div>

 

三种方式收藏日后使用

posted on 2016-03-02 22:00  金甲  阅读(996)  评论(0)    收藏  举报

导航