html/css系列 BFC

本文詳情:https://www.cnblogs.com/chen-...html

第一種 BFC中的盒子對齊spa

clipboard.png

<div class="container">
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3"></div>
        <div class="box4"></div>
    </div>
div {
                height: 20px;
        }
            
        .container {
            position: absolute;  /* 建立一個BFC環境*/
            height: auto;
            background-color: #eee;
        }
        
        .box1 {
            width: 400px;
            background-color: red;
        }
        
        .box2 {
            width: 300px;
            background-color: green;
        }
        
        .box3 {
            width: 100px;
            background-color: yellow;
            float: left;
        }
        
        .box4 {
            width: 200px;
            height: 30px;
            background-color: purple;
        }

第二種 外邊距摺疊 垂直方向上的距離由margin決定code

<div class="container">
        <div class="box"></div>
        <div class="box"></div>
    </div>
.container {
            overflow: hidden;
            width: 100px;
            height: 100px;
            background-color: red;
        }
        
        .box1 {
            height: 20px;
            margin: 10px 0;
            background-color: green;
        }
        
        .box2 {
            height: 20px;
            margin: 20px 0;
            background-color: green;
        }

clipboard.png

上下DIV同時margin 形成重疊htm

第二種BFC,由於浮動形成盒子對齊 解決方法 相隔的DIV換成P標籤blog

第三種DBC 左邊浮動右邊自適應ip

clipboard.png

第四種DFC 文字環繞 解決方法verflow:hidden清除浮動get

clipboard.png

clipboard.png

相關文章
相關標籤/搜索