最窄770px最寬1024px經典布局_網站重構教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      最典型實用的上中下,并且中間分三列的布局,這個例子有2個特點:

      1. 中間三列效果,可以任意實現單列背景色。
      2. 整體最窄770px,最寬1024px,也就是說窗口小于770xp就出底部滾動條,假如大于1024px自動屏幕居中。

      IE6.0和FF1.5測試通過

      按此在新窗口瀏覽圖片

      分析:

      最外層的wrapper把所有內容都嵌套在里邊,整體相對定位。max min已經很好的控制了最窄最寬值,但對IE沒有作用。假如沒有其他布局的穿插,這一層其實寫在body內就可以,少一層嵌套。

      #wrapper{ width:auto; border:1px solid #000; min-width:770px; max-width:1024px; text-align:left; margin-left:auto; margin-right:auto; position:relative;}

      wrapper 下級的 outer header footer

      其中header絕對定位,footer 相對定位;outer分別對左右有130px的外邊距,這是兼容非IE的要害。

      #outer{ margin-left:130px; margin-right:130px; background:silver; border-left:1px solid #000; border-right:1px solid #000; color: #000;}
      #header{ position:absolute; top:0; left:0; width:100%; height:70px; line-height:70px; border-bottom:1px solid #000; overflow:hidden; background:#0ff; text-align:center; font-size:xx-large}
      #footer { width:100%; clear:both; line-height:50px; border-top:1px solid #000; background:#ffc; color:#000; text-align:center; position:relative;}

      outer 下級的 clearheader outerwrap right clearer

      clearheader 用做填補header的空白,clearer 是一個常用的填充hack用法。
      outerwrap 寬為什么是99%,而不是100%?因為他的上層outer有邊框,100%寬再加2個邊框象素就會撐大,FF有明顯效果。
      right 的處理很經典,IE下解析為定位,FF下則為浮動。負邊距的處理也剛好使用上outer留出的空白。

      #clearheader{ height:72px;}
      .outerwrap { float:left; width:99%;}
      #right {
      position:relative;
      width:130px; float:right; left:1px;
      margin-right:-129px;
      }
      * html #right { margin-right:-130px; margin-left:-3px}
      .clearer{ height:1px; overflow:hidden; margin-top:-1px; clear:both;}

      outerwrap 內的 centrecontent left clearer 就很簡單了,思路類似上邊說明。

      <!--[if gte IE 5]> 指定IE5.0及版本以上瀏覽器有效

      使用expression方法實現對IE5.0及以上版本的寬度條件控制。

      body {width:expression( documentElement.clientWidth < 770 ? (documentElement.clientWidth == 0 ? (body.clientWidth < 770 ? "770" : "auto") : "770px") : "auto" );}
      #wrapper {width:expression( documentElement.clientWidth > 1024 ? (documentElement.clientWidth == 0 ? (body.clientWidth >1024 ? "1024" : "auto") : "1024px") : "auto" );}

      開始只想搞清楚老外是如何實現居中min max的,沒想到最后是expression,太失望了,其實這里使用腳本控制更好。另外,老外原文的 Min width of 800px 是錯的,CSS定義就是770px,后來截屏確認也是770px。

      總的來說這是一個很復雜的布局例子,融合了很多經典用法和定義,同時很傳統和實用。類似的復雜布局,四層嵌套實現對于傳統布局來說還是比較有優勢的。

      Referrence:
      3 col layout with equalising columns and footer http://www.pmob.co.uk/temp/min-max-3col.htm

      來源:一葉千鳥//所屬分類:網站重構教程/更新時間:2006-01-16
      相關網站重構教程