欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

css清除浮动的几种方法

程序员文章站 2022-05-11 08:10:39
...
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>

  <style>
   .content{
     width: 100%;
     background: #00f;
   }
   /* 方法一:通过伪类运算符
   .content::after{
     display: block;
     height: 0;
     content: "";
     visibility: hidden;
     clear: both;
   } */
   .content{
     zoom:1 ;//ie6浏览器兼容性
   }
   /* 方法二,通过在浮动元素之后添加一个空的div
   .clearfix{
     clear: both;
   } */
  .left{
    float: left;
    height: 100px;
    background: #0f0
  }
  .right{
    float: right;
    height: 100px;
    background: #0f0
  }
  </style>
</head>
<body>
  

  <div class="content">
    <div class="left">
      左边

    </div>
    <div class="right">
      右边
    </div>
    <div class="clearfix">

    </div>
  </div>
  
</body>
</html>