首先建立一個 CSS 樣式表檔,命名為 common.css,在其中加入以下代碼:
#info{border:1px solid #BCFF1D; width:960px; background:#D6FF8C url(/img/200732411541374.gif) no-repeat left top; float:left; }
#info ul{ margin:5px;width:880px}
#info li{ width:130px; height:40px; float:left;}
#info li a{ font-size:12px; font-weight:normal; line-height:35px; display:block;color:#000; text-decoration:none; padding-left:40px;background:url(/img/200732411542811.gif) no-repeat;}
#info li a:link,#info li a:visited{background-position:center top}
#info li a:hover,#info li a:active{background-position:center bottom}
接著在同一目錄下建立一個名為 img 的圖片資料夾,把需要用到的圖片放進去。
再新建一個 HTML 頁面,在 <head></head> 中導入外部樣式表的連結 common.css,並在 body 中加入以下 HTML 代碼:
<div id="info"> <ul> <li></li> <li><a href="https://www.hanwangtx.com/" target="_blank">媽媽導購</a></li> <li><a href="https://www.hanwangtx.com/index.htm" target="_blank">媽媽知識</a></li> <li><a href="https://www.hanwangtx.com/" target="_blank">媽媽部落格</a></li> </ul> </div>
用 IE 打開網頁預覽,效果如下圖:

這份寫法把樣式抽到外部 common.css,HTML 結構保持簡潔,透過 ul/li 浮動排列與背景圖定位切換,就能做出清爽美觀又易於維護的頂部導覽列。