zoukankan      html  css  js  c++  java
  • 清除浮动

    父元素没有设置高度,高度由内容撑起
    <div class="father cle">
            <div class="box1">first</div>
            <div class="box2">second</div>
        </div>
      <div class="foot"></div>
     
     

    father {
    400px;
    border: 1px solid red;
    }

    .box1 {
    100px;
    height: 100px;
    background-color: cornflowerblue;
    }

    .box2 {
    100px;
    height: 100px;
    background-color: deepskyblue;
    }

    .foot {
    500px;
    height: 200px;
    background-color: cadetblue;
    }

    当给子元素设置float:left时

    1.此时父元素的高度没有了,可以在父元素中添加内容(再添加一个div,给这个div设置clear:both)

    <div class="father cle">
            <div class="box1">first</div>
            <div class="box2">second</div>
            <div class="box3">third</div>
        </div>
        <div class="foot"></div>
    .father {
                 400px;
                border: 1px solid red;
            }
            
            .box1 {
                 100px;
                height: 100px;
                background-color: cornflowerblue;
                float: left;
            }
            
            .box2 {
                 100px;
                height: 100px;
                background-color: deepskyblue;
                float: left;
            }
            
            .foot {
                 500px;
                height: 200px;
                background-color: cadetblue;
            }
            
            .box3 {
                clear: both;
            }

     2.再父元素中设置overflow:hidden

     3.设置after伪类

    <div class="father cle">
            <div class="box1">first</div>
            <div class="box2">second</div>
            
        </div>
        <div class="foot"></div>
     
     .cle:after {
                content: "";
                display: block;
                height: 0;
                clear: both;
                visibility: hidden;
            }
            
            .cle {
                *zoom: 1;
            }

     

    4.使用after和before双伪类

     .cle:after,
            .cle:before {
                content: "";
                display: table
            }
            
            .cle:after {
                clear: both;
            }
            
            .cle {
                *zoom: 1;
            }
    <div class="father cle">
            <div class="box1">first</div>
            <div class="box2">second</div>
            
        </div>
        <div class="foot"></div>
  • 相关阅读:
    VSCode Web Developement for Javascript. Must have plugins.
    Docker explainations
    如何在启用SharePoint浏览器功能的InfoPath 表单中添加托管代码以动态地加载并显示图片
    解决方案:带格式化文本控件( RichText)的模板如果在InfoPath的浏览器中加载可能出现 COM 组件的80040154错误
    springboot之本地缓存(guava与caffeine)
    java基础之泛型对象与json互转
    nginx动静分离
    网关鉴权后下游统一filter获取用户信息
    网关高可用之keepavlived全流程(安装/配置/验证/解析)
    微服务时代之网关及注册中心高可用架构设计
  • 原文地址:https://www.cnblogs.com/zhanghaifeng123/p/11703261.html
Copyright © 2011-2022 走看看