以下示範一個註冊流程表單:頂部是步驟指示器,目前步驟以白底藍框高亮,下方是對應的表單欄位。視覺重點在於步驟的橫向排列與選中態的呈現。
<div id="reg">
<h6>歡迎您註冊會員!</h6>
<div id="menu">
<ul>
<li>確認服務條款</li>
<li class="current">選擇用戶名</li>
<li>選擇用戶類型</li>
<li>填寫詳細資料</li>
</ul>
</div>
<div id="content">
<form>
<dl>
<dt>用戶名</dt>
<dd><input type="text" /></dd>
<dt>密碼</dt>
<dd><input type="password" /></dd>
<dt>確認密碼</dt>
<dd><input type="password" /></dd>
<dt></dt>
<dd><input type="button" value="註冊" /></dd>
</dl>
</form>
</div>
</div>
* { font-size: 12px; padding: 0; margin: 0; }
body { text-align: center; }
#reg {
margin: 0 auto;
width: 600px;
background: #ccc;
height: 500px;
}
h6 {
background: #000;
height: 28px;
color: #fff;
text-align: left;
line-height: 28px;
padding-left: 3px;
}
#menu {
height: 30px;
text-align: left;
padding: 15px 0 0 10px;
overflow: hidden;
}
li { list-style-type: none; }
#menu li {
float: left;
color: green;
height: 30px;
padding: 0 5px;
line-height: 30px;
margin-left: 20px;
}
.current {
border: 1px solid blue;
border-bottom: 0;
background: white;
}
#content {
border: 1px solid blue;
height: 400px;
margin: 8px 8px 0;
background: white;
padding: 10px;
}
表單標籤與控制項成對出現,正好對應 dl 的 dt(術語)與 dd(定義),語義上比 table 更貼切:
#content dl {
border-top: 1px solid #ccc;
border-left: 1px solid #ccc;
width: 560px;
}
#content dl dt,
#content dl dd {
border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
height: 28px;
}
#content dl dt {
width: 200px;
float: left;
text-align: right;
padding-right: 3px;
background: #F0F0F0;
line-height: 28px;
}
#content dl dd {
width: 352px;
float: left;
text-align: left;
padding-left: 3px;
}
/* 舊版 IE 的間距修正 */
#content dl dd div { padding-top: 3px; }
外層只畫上邊框與左邊框,每個 dt / dd 再補右與下邊框,就能拼出完整的表格線,而不必真的使用 table。
原始示範用一段 JavaScript 在 window.onload 時逐一設定每個 li 的 left 來排布步驟,其實完全沒有必要——改用 float:left 加上統一的 margin-left 就能達到相同效果,不必靠絕對定位與硬編碼座標。另外,密碼欄位應使用 type="password" 而非 text,這是原範例中值得修正的一處。