CSS+DIV自適應高度布局

來源:互聯網
上載者:User
css|自適應

要實現的是head foot固定,中間地區隨內容高度自適應,拖動捲軸時foot永遠居底。



SolarDreamStudios的方案給了我一個很好的思路,但關鍵區段是原創的,一直以為會比SolarDreamStudios的方案好,結果仔細看他們的代碼,才發現其實原理都差不多,不過他們似乎在相容性上下了更多工夫,具體未測試。

A. 寬度100%自適應

結構代碼

<body>

<div id="head">head</div>
<div id="head_height"></div>

<div id="middle"></div>

<div id="foot_height"></div>
<div id="foot">foot</div>

</body>
表現代碼
#head { width:100%; text-align:center; background:#FF9400; height:100px; position:absolute; top:0;}
  #head_height { height:100px;}
#middle { margin:20px;}
#foot { width:100%; text-align:center; background:#f00; height:100px; position:absolute; bottom:0;}
* html #foot { bottom:-1px;}
  #foot_height { height:100px;}

B. 寬度固定置中

結構代碼
<body>

<div id="head">
  <div id="head_content">head</div>
</div>
<div id="head_height"></div>

<div id="middle"></div>

<div id="foot_height"></div>
<div id="foot">
  <div id="foot_content">foot</div>
</div>

</body>
表現代碼
#head { width:100%; text-align:center; position:absolute; top:0; left:0;}
  #head_content { line-height:100px; width:700px; margin:0 auto; background:#FF9400; height:100px;}
  #head_height { height:100px;}
#middle { margin:20px;}
#foot { width:100%; text-align:center; position:absolute; bottom:0;}
* html #foot { bottom:-1px;}
  #foot_content { line-height:100px; width:700px; margin:0 auto; background:#f00; height:100px;}
  #foot_height { height:100px;}
測試環境IE6.0和FF1.5,IE環境下因為BUG有時會自動出現捲軸(SolarDreamStudios的方案一樣),FF下為完美效果。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.