HTML 布局
在網(wǎng)絡(luò)上,隨處都可以看到像報紙那樣的格式化分欄。
大多數(shù)網(wǎng)站可以使用 <div> 或者 <table> 元素來創(chuàng)建多列。CSS 用于對元素進行定位,或者為頁面創(chuàng)建背景以及色彩豐富的外觀。
使用 <div> 元素來布局
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <div id="container" style="width:500px"> <div id="header" style="background-color:#00FFFF;"> <h1 style="margin-bottom:0;">標題</h1></div> <div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;"> <b>菜單</b><br> HTML<br> CSS<br> </div> <div id="content" style="background-color:#00FF00;height:200px;width:400px;float:left;"> 內(nèi)容</div> <div id="footer" style="background-color:#FF00FF;clear:both;text-align:center;"> 版權(quán) ? php.cn</div> </div> </body> </html>
使用表格來進行布局
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <table width="500" border="0"> <tr> <td colspan="2" style="background-color:#FFA500;"> <h1>標題</h1> </td> </tr> <tr> <td style="background-color:#FFD700;width:100px;"> <b>菜單</b><br> HTML<br> CSS<br> </td> <td style="background-color:#eeeeee;height:200px;width:400px;"> 內(nèi)容</td> </tr> <tr> <td colspan="2" style="background-color:#FFA500;text-align:center;"> 版權(quán) ? php.cn</td> </tr> </table> </body> </html>
HTML 布局 - 有用的提示
Tip: 使用 CSS 最大的好處是,如果把 CSS 代碼存放到外部樣式表中,那么站點會更易于維護。通過編輯單一的文件,就可以改變所有頁面的布局。如需學(xué)習(xí)更多有關(guān) CSS 的知識,請訪問我們的CSS 教程.
Tip: 由于創(chuàng)建高級的布局非常耗時,使用模板是一個快速的選項。通過搜索引擎可以找到很多免費的網(wǎng)站模板(您可以使用這些預(yù)先構(gòu)建好的網(wǎng)站布局,并優(yōu)化它們)。