zoukankan      html  css  js  c++  java
  • 盼盼Degenerate——清除浮动的方法

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    </head>
    <style type="text/css">
    *{
    margin: 0;
    padding: 0;
    }
    li{
    list-style: none;
    }
    header{
    100%;
    background: orange;
    text-align: center;
    font-size: 24px;
    padding: 10px 0;
    }

    .box{
    100%;
    border: 2px solid #000000;
    }


    .box li{
    25%;
    height: 100px;
    background: pink;
    float: left;
    margin: 10px ;
    }
    div.carousel{
    100%;
    height: 300px;
    background: aquamarine;
    }
    footer{
    100%;
    position: fixed;
    bottom: 0;
    background: orange;
    text-align: center;
    font-size: 24px;
    padding: 10px 0;
    }
    </style>
    <body>
    <header>头部</header>
    <ul class="box">
    <li></li>
    <li></li>
    <li></li>
    </ul>
    <div class="carousel">
    </div>
    <footer>底部</footer>
    </body>
    </html>

    此时在浏览器中的样式

    第一种方法

    使用overflow: hidden;

    给父元素添加overflow: hidden;

     第二种方法

    在子元素后边添加一个空div

    <ul class="box">
    <li></li>
    <li></li>
    <li></li>
    <div class="clearfix"></div>
    </ul>

    css样式

    .clearfix{
    clear: both;
    }

    第三种使用伪元素

    css代码

    .box:after{
    content: '';
    display: block;
    clear: both;
    }

    第四种浮动父元素

    .box{
    100%;
    border: 2px solid #000000;
    float: left;
    }

    但是此时在浏览器我们可以看到并不是我们想要的效果

     为了解决这个问题 我们在父元素下面添加一个空div

    <body>
    <header>头部</header>
    <ul class="box">
    <li></li>
    <li></li>
    <li></li>
    </ul>
    <div class="clearfix"></div>
    <div class="carousel">
    </div>
    <footer>底部</footer>
    </body>

     css样式

    .clearfix{
    clear: both;
    }

    这样就解决了这个问题

  • 相关阅读:
    input 框变成不可编辑的。
    git 首次往远程仓库提交项目过程。(使用idea操作)
    nacos 导入项目配置(yml文件)步骤
    instr MySQL数据库函数用法
    遍历 map 的方法
    基于分布式思想下的rpc解决方案(1)
    深入理解通信协议-(1)
    Tomcat(3)--性能优化
    并发编程(5)--并发容器
    并发编程(4)--显示锁和AQS
  • 原文地址:https://www.cnblogs.com/panpan-degenerate/p/7435555.html
Copyright © 2011-2022 走看看