zoukankan      html  css  js  c++  java
  • 清除浮动的方法?

    (1)给父级元素单独定义高度(height)

    (2)在标签结尾处加空div标签 clear:both

    .clear{clear: both;}

    <div class="box">

           <div class="red">1</div>
           <div class="sienna">2</div>
           <div class="blue">3</div>
           <div class="clear"></div>
     </div>

    (3)父级div定义 overflow:hidden

    使用伪元素来清除浮动(:after,注意:作用于浮动元素的父亲)

    主要推荐使用这种方法清除浮动

    .clearfix:after{
              content:"";/*设置内容为空*/
              height:0;/*高度为0*/
              line-height:0;/*行高为0*/
              display:block;/*将文本转为块级元素*/
              visibility:hidden;/*将元素隐藏*/
              clear:both;/*清除浮动*/
          }
         .clearfix{
              zoom:1;/*为了兼容IE*/
         }

     <body>

    <div class="box clearfix">
        <div class="red">1</div>
        <div class="sienna">2</div>
        <div class="blue">3</div>
    </div>

     </body>

    (4)使用双伪元素清除浮动

    .clearfix:before,.clearfix:after {
         content: "";
         display: block;
         clear: both;
    }
    .clearfix {
         zoom: 1;
     }

  • 相关阅读:
    UVa532 Dungeon Master 三维迷宫
    6.4.2 走迷宫
    UVA 439 Knight Moves
    UVa784 Maze Exploration
    UVa657 The die is cast
    UVa572 Oil Deposits DFS求连通块
    UVa10562 Undraw the Trees
    UVa839 Not so Mobile
    327
    UVa699 The Falling Leaves
  • 原文地址:https://www.cnblogs.com/HYTing/p/12721635.html
Copyright © 2011-2022 走看看