設計流程
- 構思與線框圖:先在 Photoshop/Fireworks 繪製版面草圖。
- 區塊規劃:拆解為 Header、Sidebar、Main、Footer 等模組。
- DIV 結構樹:建立語意化巢狀結構。
- 編寫 HTML:優先寫結構,再引入 CSS。
- 撰寫 CSS:由大到小、由佈局到細節。
版面規劃示意



DIV 結構樹
body
└─ #container /* 頁面容器 */
├─ #header /* 頁首:Logo、選單、Banner */
├─ #pageBody /* 頁身 */
│ ├─ #sidebar /* 側邊欄 */
│ └─ #mainBody /* 主內容 */
└─ #footer /* 頁尾:版權資訊 */
HTML 骨架 (index.htm)
<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Div+CSS 佈局練習</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<div id="header"><!-- 頁首 --></div>
<div id="pageBody">
<div id="sidebar"><!-- 側邊欄 --></div>
<div id="mainBody"><!-- 主內容 --></div>
</div>
<div id="footer"><!-- 頁尾 --></div>
</div>
</body>
</html>
基礎 CSS (css.css)
/* 重置與基礎 */
body { font: 12px Tahoma; margin: 0; text-align: center; background: #fff; }
/* 容器 */
#container { width: 100%; }
/* 頁首 */
#header { width: 800px; margin: 0 auto; height: 100px; background: #ffcc99; }
/* 頁身 */
#pageBody { width: 800px; margin: 0 auto; height: 400px; background: #ccff00; }
/* 頁尾 */
#footer { width: 800px; margin: 0 auto; height: 50px; background: #00ffff; }
後續擴充方向
- 將固定寬度改為
max-width: 1200px + width: 90% 實現響應式。
- 側邊欄與主內容改用 Flexbox:
#pageBody { display: flex; }。
- 加入 CSS 變數管理色系、間距,提升維護性。