DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> WEB網站前端 >> 關於網頁技巧 >> 網頁最窄770px最寬1024px經典布局
網頁最窄770px最寬1024px經典布局
編輯:關於網頁技巧     
最典型實用的上中下,並且中間分三列的布局,這個例子有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

附:布局代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>最窄770px最寬1024px的經典布局</title>
<meta http-equiv="Content-Type" content="te

123下一頁
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved