先看一下成品:

這是一個黑底、直角、帶左右圓角收邊的水平選單,滑鼠移入與目前所在頁都有各自的視覺回饋。整份程式碼如下。
#pointermenu {
border-top: 7px solid black; /* 頂部的粗橫線,可選 */
margin: 0;
padding: 0;
}
#pointermenu ul {
margin: 0;
margin-left: 15px; /* 整個選單距左邊緣的距離 */
float: left;
padding-left: 10px;
font: 12px 宋體;
background-color: black;
background: black url(../images/leftround.gif) bottom left no-repeat; /* 左側圓角 */
}
* html #pointermenu ul { /* 僅 IE6:縮小左邊距並補上 1em 下邊距 */
margin-bottom: 1em;
margin-left: 7px;
}
#pointermenu ul li {
display: inline;
}
#pointermenu ul li a {
float: left;
color: white;
padding: 2px 11px 7px 7px;
text-decoration: none;
background: url(../images/bbbbb.gif) bottom center no-repeat;
}
#pointermenu ul li a:visited {
color: white;
}
#pointermenu ul li a:hover,
#pointermenu ul li a#selected { /* 移入與目前頁 */
color: white;
background-color: darkred;
}
#pointermenu ul li a#rightcorner {
padding-right: 0;
padding-left: 8px;
background: url(../images/rightround.gif) bottom right no-repeat; /* 右側圓角 */
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" lang="gb2312" xml:lang="gb2312">
<head>
<title>站酷 CSS 代碼演示</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" type="text/css" href="css/css.css" />
</head>
<body>
<div id="pointermenu">
<ul>
<li><a href="#">主 頁</a></li>
<li><a href="#">自定菜單</a></li>
<li><a href="#" id="selected">自定菜單</a></li>
<li><a href="#">自定菜單</a></li>
<li><a href="#">自定菜單</a></li>
<li><a href="#">自定菜單</a></li>
<li><a href="#">自定菜單</a></li>
<li><a href="#">自定菜單</a></li>
<li><a href="#" id="rightcorner"> </a></li>
</ul>
</div>
<br style="clear: left" />
</body>
</html>
li 用 display: inline,a 用 float: left。兩者搭配是為了讓項目橫向排列,同時避開 IE6 的雙倍 margin bug。這在當年是標準手法。
左右圓角是兩張獨立的小圖。左端掛在 ul 的背景,右端掛在一個空連結 id="rightcorner" 上,靠 padding 把它撐出位置。用一個「假連結」來掛背景圖,是 CSS3 之前做圓角的常見变通。
id="selected" 標記當前頁。這個 id 在每個頁面各自指向不同的選項,選單的樣式檔共用一份即可,不需要為每頁複製樣式。
* html 是 IE6 專屬 hack。IE6 不認這個語法,其他瀏覽器會跳過,因此裡面的修正只對 IE6 生效。
最後的 <br style="clear: left" /> 用來收掉浮動。今天我們會用 clear: both 的 clearfix,或直接讓父容器 display: flow-root。
.menu {
display: flex;
gap: 0;
background: #000;
border-radius: 0 0 8px 8px; /* 圓角一次搞定,不需要圖片 */
overflow: hidden;
}
.menu a {
display: block;
padding: 9px 18px;
color: #fff;
text-decoration: none;
}
.menu a:hover,
.menu a[aria-current="page"] {
background: darkred;
}
同樣的效果,從二十幾行 hack 縮到十行,而且沒有任何圖片、沒有前綴、也不需要 IE 專屬修正。border-radius 取代了兩張圓角圖,flexbox 取代了浮動與 inline 混搭,aria-current="page" 則同時解決了語意與樣式——螢幕閱讀器現在能告訴使用者「你在目前頁」。
這正是標準演進的價值:早年我們用創意繞過限制,而後標準把那些創意收編成一行屬性。