頁面布局

高度已知,三欄布局,左右各300px,中間自適應(yīng),能夠?qū)崿F(xiàn)的方法

1.float方法

     <section class="layout float">
        <style>
            .left-right-center>div{
                height:100px;
            }
            .layout.float .left{
                width: 300px;
                float:left;
                background:red;
            }
            .layout.float .right{
                width: 300px;
                float: right;
                background:yellow;
            }
            .layout.float .center{
                background: skyblue;
            }
        </style>
        <article class="left-right-center">
            <div class="left"></div>
            <div class="right"></div>
            <div class="center">float方法</div>
        </article>
    </section>

2.絕對定位

  <section class="layout position">
        <style>
            .layout.position .left-right-center>div{
                height: 100px;
                position: absolute;
            }
            .layout.position .left{
                left:0px;
                width:300px;
                background: red;
            }
            .layout.position .right{
                right:0;
                width: 300px;
                background:yellow;
            }
            .layout.position .center{
                left:300px;
                right: 300px;
                background:skyblue;
            }
        </style>
        <article class="left-right-center">
            <div class="left"></div>
            <div class="center">絕對定位</div>
            <div class="right"></div>
        </article>
    </section>

3.flex

     <section class="layout flex">
        <style>
            .layout.flex{
                margin-top: 140px;
            }
            .layout.flex .left-center-right{
                display:flex;
                height:100px;
            }
            .layout.flex .left{
                width: 300px;
                background:red;
            }
            .layout.flex .center{
                flex:1;
                background:skyblue;
            }
            .layout.flex .right{
                width: 300px;
                background: yellow;
            }
        </style>
        <article class="left-center-right">
            <div class="left"></div>
            <div class="center">flex</div>
            <div class="right"></div>
        </article>
    </section>

4.table

<section class="layout table">
        <style>
            .layout.table .left-center-right{
                height:100px;
                width:100%;
                display: table;
            }
            .layout.table .left-center-right>div{
                display: table-cell;
            }
            .layout.table .left{
                width:300px;
                background: red;
            }
            .layout.table .center{
                background: skyblue;
            }
            .layout.table .right{
                width: 300px;
                background:yellow;
            }
        </style>
        <article class="left-center-right">
            <div class="left"></div>
            <div class="center">table布局</div>
            <div class="right"></div>
        </article>
    </section>

5.grid

<section class="layout grid">
        <style>
            .layout.grid .left-center-right{
                display: grid;
                grid-template-columns: 300px auto 300px;
                grid-template-rows: 100px;
            }
            .layout.grid .left{
                background: red;
            }
            .layout.grid .center{
                background: skyblue;
            }
            .layout.grid .right{
                background:yellow;
            }
        </style>
        <article class="left-center-right">
            <div class="left"></div>
            <div class="center">grid</div>
            <div class="right"></div>
        </article>
    </section>

ps:清除浮動

方案1:

overflow:hidden;

這樣可以清除浮動,但是也存在較大弊端,如果父級內(nèi)容超出會被隱藏

方案2:給浮動元素下方條件一個空的div,給div單獨加個樣式

  clear:both; 
  height:0; 
  overflow:hidden;

但是這個就需要在頁面上新增標(biāo)簽,影響頁面的加載

方案3:萬能清除浮動法

::afer{ 
  content:' '; 
  clear: both; 
  height:0; 
  overflow:hidden; 
  visibility:hidden; 
  display:block;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 頁面布局 題:假設(shè)高度已知,請寫出三欄布局,其中左欄右欄寬各位300px,中間自適應(yīng)。答: 7種方法1.浮動 2....
    noyanse閱讀 561評論 0 0
  • 本文主要講述頁面布局樣式方面涉及的知識點,更全面的對CSS相應(yīng)的技術(shù)進行歸類、整理、說明,沒有特別詳細(xì)的技術(shù)要點說...
    Joel_zh閱讀 1,175評論 0 1
  • 題目: 假設(shè)高度已知,請寫出三欄布局,其中左欄右欄高度各為300px,中間自適應(yīng) 慕課網(wǎng)視頻 能寫出有幾種方案? ...
    邢走在云端閱讀 334評論 0 4
  • 說起前端開發(fā),首先會想到頁面布局,作為資深前端來說,用頁面布局來談前端可能會認(rèn)為太淺顯,但作為前端開發(fā)中最基礎(chǔ)的技...
    希緦婷閱讀 443評論 0 1
  • 頁面布局 題目:假設(shè)高度已知,請寫出三欄布局,其中左欄、右欄寬度各為300px,中間自適應(yīng) 1、float 絕對定...
    飛菲fly閱讀 1,653評論 2 4

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