• <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>

    移動端布局上下固定中間自適應

    移動端結構上下固心猿意馬中心自順應,本家兒要運用的css為flex。

    經由過程flex的屬性flex:1;  實現中心區域拉伸,獲得自順應結果。

    東西/原料

    • 代碼編纂器
    • html、css(本家兒如果flex)

    方式/步調

    1. 1

      第一步:界說本家兒體布局

      界說一個div中包含三個小div

      年夜div樣式:

      display: flex;

      flex-direction:column; 

    2. 2

      第二步:上下固心猿意馬

      頂部與底部樣式 固心猿意馬定位 position:fixed; 

      頂部top: 0px;

      底部bottom: 0px; 

    3. 3

      第三步:中心自順應

      中心自順應區域樣式

      flex:1;  

      overflow: scroll;

    4. 4

      第四步:要在樣式表中添加 html,body{height:100%;} 

      原因:讓中心區域有個高度可以擔當

    5. 5

      第五步:完整代碼

      <!doctype html>

      <html>

      <head>

      <meta charset="UTF-8">

      <meta name="viewport" content="width=device-width, initial-scale=1.0">

      <title>百度經驗</title>  

      <style type="text/css">  

      *{

      margin: 0;

      padding: 0;

      html,body{height:100%;} 

      body{ 

      font-family: 微軟雅黑;

      background-color: #f4f4f4; 

      .demon{

      display: flex;

      flex-direction:column; 

      height: 100%; 

      }  

      .fixed{

      width: 100%; 

      line-height: 45px;

      font-size: 16px;

      background-color: #0088ee;

      color: #fff;

      text-align: center;

      position: fixed;

      }

      .fixTop{  

      top: 0px;

      }

      .fixBottom{ 

      bottom: 0px; 

      }

      .container2{  

      flex:1; 

      margin: 55px 10px ;

      background-color: #fff;

      overflow: scroll;

      }

      </style>

      </head> 

      <body >

      <div>

          <div class="fixed fixTop"> 

           <span>頂部文字</span>

          </div> 

          <div>

               <p>hahaha</p>   

          </div> 

          <div class="fixed fixBottom"> 

              <span>底部文字</span>

          </div>  

      </div>   

      </body>

      </html>  

       

       

        

    注重事項

    • 必然在樣式表中添加 html,body{height:100%;}
    • 理解flex
    • 發表于 2018-11-22 00:00
    • 閱讀 ( 952 )
    • 分類:其他類型

    你可能感興趣的文章

    相關問題

    0 條評論

    請先 登錄 后評論
    聯系我們:uytrv@hotmail.com 問答工具
  • <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>
    久久久久精品国产麻豆