3-1頁面布局

題目:假設(shè)高度已知,請(qǐng)寫出三欄布局,其中左欄、右欄寬度各為300px,中間自適應(yīng)

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Layout</title>
    <style media="screen">
      html *{
        padding: 0;
        margin: 0;
      }
      .layout article div{
        min-height: 100px;
      }
    </style>
  </head>
  <body>
    <!--浮動(dòng)布局  -->
    <section class="layout float">
      <style media="screen">
      .layout.float .left{
        float:left;
        width:300px;
        background: red;
      }
      .layout.float .center{
        background: yellow;
      }
      .layout.float .right{
        float:right;
        width:300px;
        background: blue;
      }
      </style>
      <h1>三欄布局</h1>
      <article class="left-right-center">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center">
          <h2>浮動(dòng)解決方案</h2>
          1.這是三欄布局的浮動(dòng)解決方案;
          2.這是三欄布局的浮動(dòng)解決方案;
          3.這是三欄布局的浮動(dòng)解決方案;
          4.這是三欄布局的浮動(dòng)解決方案;
          5.這是三欄布局的浮動(dòng)解決方案;
          6.這是三欄布局的浮動(dòng)解決方案;
        </div>
      </article>
    </section>

    <!-- 絕對(duì)布局 -->
    <section class="layout absolute">
      <style>
        .layout.absolute .left-center-right>div{
          position: absolute;
        }
        .layout.absolute .left{
          left:0;
          width: 300px;
          background: red;
        }
        .layout.absolute .center{
          left: 300px;
          right: 300px;
          background: yellow;
        }
        .layout.absolute .right{
          right:0;
          width: 300px;
          background: blue;
        }
      </style>
      <h1>三欄布局</h1>
      <article class="left-center-right">
        <div class="left"></div>
        <div class="center">
          <h2>絕對(duì)定位解決方案</h2>
          1.這是三欄布局的浮動(dòng)解決方案;
          2.這是三欄布局的浮動(dòng)解決方案;
          3.這是三欄布局的浮動(dòng)解決方案;
          4.這是三欄布局的浮動(dòng)解決方案;
          5.這是三欄布局的浮動(dòng)解決方案;
          6.這是三欄布局的浮動(dòng)解決方案;
        </div>
        <div class="right"></div>
      </article>
    </section>


    <!-- flexbox布局 -->
    <section class="layout flexbox">
      <style>
        .layout.flexbox{
          margin-top: 110px;
        }
        .layout.flexbox .left-center-right{
          display: flex;
        }
        .layout.flexbox .left{
          width: 300px;
          background: red;
        }
        .layout.flexbox .center{
          flex:1;
          background: yellow;
        }
        .layout.flexbox .right{
          width: 300px;
          background: blue;
        }
      </style>
      <h1>三欄布局</h1>
      <article class="left-center-right">
        <div class="left"></div>
        <div class="center">
          <h2>flexbox解決方案</h2>
          1.這是三欄布局的浮動(dòng)解決方案;
          2.這是三欄布局的浮動(dòng)解決方案;
          3.這是三欄布局的浮動(dòng)解決方案;
          4.這是三欄布局的浮動(dòng)解決方案;
          5.這是三欄布局的浮動(dòng)解決方案;
          6.這是三欄布局的浮動(dòng)解決方案;
        </div>
        <div class="right"></div>
      </article>
    </section>


    <!-- 表格布局 -->
    <section class="layout table">
      <style>
        .layout.table .left-center-right{
          width:100%;
          height: 100px;
          display: table;
        }
        .layout.table .left-center-right>div{
          display: table-cell;
        }
        .layout.table .left{
          width: 300px;
          background: red;
        }
        .layout.table .center{
          background: yellow;
        }
        .layout.table .right{
          width: 300px;
          background: blue;
        }
      </style>
      <h1>三欄布局</h1>
      <article class="left-center-right">
        <div class="left"></div>
        <div class="center">
          <h2>表格布局解決方案</h2>
          1.這是三欄布局的浮動(dòng)解決方案;
          2.這是三欄布局的浮動(dòng)解決方案;
          3.這是三欄布局的浮動(dòng)解決方案;
          4.這是三欄布局的浮動(dòng)解決方案;
          5.這是三欄布局的浮動(dòng)解決方案;
          6.這是三欄布局的浮動(dòng)解決方案;
        </div>
        <div class="right"></div>
      </article>
    </section>

    <!-- 網(wǎng)格布局 -->
    <section class="layout grid">
      <style>
        .layout.grid .left-center-right{
          width:100%;
          display: grid;
          grid-template-rows: 100px;
          grid-template-columns: 300px auto 300px;
        }
        .layout.grid .left-center-right>div{

        }
        .layout.grid .left{
          width: 300px;
          background: red;
        }
        .layout.grid .center{
          background: yellow;
        }
        .layout.grid .right{

          background: blue;
        }
      </style>
      <h1>三欄布局</h1>
      <article class="left-center-right">
        <div class="left"></div>
        <div class="center">
          <h2>網(wǎng)格布局解決方案</h2>
          1.這是三欄布局的浮動(dòng)解決方案;
          2.這是三欄布局的浮動(dòng)解決方案;
          3.這是三欄布局的浮動(dòng)解決方案;
          4.這是三欄布局的浮動(dòng)解決方案;
          5.這是三欄布局的浮動(dòng)解決方案;
          6.這是三欄布局的浮動(dòng)解決方案;
        </div>
        <div class="right"></div>
      </article>
    </section>
 </body>
</html>

1.每個(gè)方案的優(yōu)缺點(diǎn)
2 .假如把高度去掉,那個(gè)方案不再適用了
3.兼容性到業(yè)務(wù)中那個(gè)最實(shí)用

浮動(dòng):清除浮動(dòng) 與其周邊的元素的關(guān)系處理好。兼容性好;
絕對(duì)定位:快捷;缺點(diǎn):導(dǎo)致子元素脫離文檔流,可使用性差;
flex: 是為了解決上述兩個(gè)問題而解決的。相對(duì)是比較完美的;
table布局:兼容性比較好。缺點(diǎn):一個(gè)高度被撐開,其他的也會(huì)受影響;
網(wǎng)格布局:新的技術(shù)布局。
float 增加高度解決辦法添加bfc.

小結(jié)

1.語義化掌握到位
2.頁面布局理解深刻
3.CSS基礎(chǔ)知識(shí)扎實(shí)
4.思維靈活且積極向上
5.代碼書寫規(guī)范

最后編輯于
?著作權(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)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標(biāo)簽?zāi)J(rèn)的外補(bǔ)...
    _Yfling閱讀 14,199評(píng)論 1 92
  • 一:在制作一個(gè)Web應(yīng)用或Web站點(diǎn)的過程中,你是如何考慮他的UI、安全性、高性能、SEO、可維護(hù)性以及技術(shù)因素的...
    Arno_z閱讀 1,372評(píng)論 0 1
  • 前言 現(xiàn)在,我們被稱為前端工程師。然而,早年給我們的稱呼卻是頁面仔。或許是職責(zé)越來越大,整體的前端井噴式的發(fā)展,使...
    Calvin李閱讀 594評(píng)論 0 0
  • 樹欲靜,風(fēng)不止 2017.5.16 船長(zhǎng)問我,你端午回家嗎。 我說,我端午假期過生日謝謝,勞資沒空。 ——那我請(qǐng)你...
    竹紙竹紙大竹紙閱讀 165評(píng)論 0 0
  • 小馬云要改我微信的備注 改成蘑菇的彩虹,也是不要太中二,也很沒有創(chuàng)意,一點(diǎn)不夠浪漫。 今天早上突然發(fā)現(xiàn),我可以吃不...
    Louirose閱讀 704評(píng)論 0 0

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