1. 程式人生 > >高度自適應,內容是浮動元素

高度自適應,內容是浮動元素

flow wrap con after 方法 splay content height borde

可以有兩種方法:

1.添加overflow:hidden;

2.添加偽元素

<style>

  .wrap{
    border:1px solid blue;
    width:600px;
    margin:0 auto;
    padding:20px 0;
  }
  .main{
    float:left;
    background:pink;
    width:350px;
    height:100px;
  }
  .side{
    float:left;
    background:rosybrown;
    width:200px;
    height:100px;
  }
  .wrap:after{


    content:‘‘;
    display:block;
    height:0;
    clear:both;
  }
</style>

<div class="wrap">

  <div class="main"></div>

  <div class="side"></div>
</div>

高度自適應,內容是浮動元素