三欄布局

三欄布局將主頁(yè)分成3部分左中右,左右定寬,中間自適應(yīng)

1.浮動(dòng)實(shí)現(xiàn)
兼容好,易實(shí)現(xiàn)
左右浮動(dòng),再寫(xiě)中間,需要去浮動(dòng)

<style>
        .left {
            width: 100px;
            height: 100px;
            background: lightcoral;
            float: left;
        }
        .right {
            width: 100px;
            height: 100px;
            background: lightskyblue;
            float: right;
        }
        .center {
            margin: 0 100px;
            height: 100px;
            background: mediumpurple;
        }
    </style>
    <div class="left"></div>
    <div class="right"></div>
    <div class="center"></div>

2.定位實(shí)現(xiàn)
左右分別定位兩側(cè),中間左右margin 和左右寬度一致
脫離文檔流,順序正常

 <style>
        *{
            margin:0;
            padding: 0;
        }
        .left {
            width: 100px;
            height: 100px;
            background: lightcoral;
            position: absolute;
            left: 0;
            right: 0;
        }
        .right {
            width: 100px;
            height: 100px;
            background: lightskyblue;
            position: absolute;
            right: 0;
            top: 0;
        }
        .center {
            height: 100px;
            background: mediumorchid;
            margin: 0 100px;
        }
   </style>
    <div class="left"></div>
    <div class="center"></div>
    <div class="right"></div>

3.flex實(shí)現(xiàn)

<style>
        *{
            margin:0;
            padding: 0;
         }
        .container {
            display: flex;
        }
        .left {
            width: 100px;
            height: 100px;
            background: lightskyblue;
        }
        .right {
            width: 100px;
            height: 100px;
            background: orangered;
        }
        .center {
            height: 100px;
            background: orchid;
            flex: 1;
        }
    </style>
   <div class="container">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </div>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容