最窄770px最寬1024px經典布局

來源:互聯網
上載者:User

最典型實用的上中下,並且中間分三列的布局,這個例子有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



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.