下單、註冊、資料填報這類流程,幾乎都會配一條步驟進度條,讓用戶清楚自己走到哪一步。

做法並不複雜:把每個步驟之間的箭頭從設計圖裡切出來作為背景,再用 background-image 定位箭頭、background-color 填充底色。進度條通常有三種狀態:
針對這三種狀態給 li 掛不同的 class,樣式自然分流。此外還有一個 current_prev 狀態,用來處理「當前步驟的箭頭要顯示為已完成色」這種過渡情況。
結構:
<div class="flow_steps">
<ul>
<li class="done">第一步</li>
<li class="current_prev">第二步</li>
<li class="current">第三步</li>
<li>第四步</li>
<li class="last">第五步</li>
</ul>
</div>
樣式:
.flow_steps ul li {
float:left;
height:23px;
padding:0 40px 0 30px;
line-height:23px;
text-align:center;
background:url(../images/barbg.png) no-repeat 100% 0 #E4E4E4;
font-weight:bold;
}
.flow_steps ul li.done { background-position:100% -46px; background-color:#FFEDA2; }
.flow_steps ul li.current_prev { background-position:100% -23px; background-color:#FFEDA2; }
.flow_steps ul li.current { color:#fff; background-color:#990D1B; }
.flow_steps ul li.last { background-image:none; }
背景切片(PNG):

最終效果:

結構:
<div class="steps_bar">
<ul>
<li class="done"><span>STEP 1</span></li>
<li class="current_prev"><span>STEP 2</span></li>
<li class="current"><span>STEP 3</span></li>
<li><span>STEP 4</span></li>
<li class="last"><span>STEP 5</span></li>
</ul>
</div>
樣式:
.steps_bar ul { border-left:solid 1px #ccc; overflow:hidden; }
.steps_bar ul li {
float:left;
height:60px;
padding-right:19px;
line-height:60px;
text-align:center;
background:url(../images/stepbar.png) no-repeat 100% 0 #f1f1f1;
font-weight:bold;
}
.steps_bar ul li span {
display:block;
height:58px;
padding:0 30px;
background:#f1f1f1;
border-top:solid 1px #ccc;
border-bottom:solid 1px #ccc;
}
.steps_bar ul li.done { color:#fff; background-position:100% -120px; background-color:#646464; }
.steps_bar ul li.current_prev { color:#fff; background-position:100% -60px; background-color:#646464; }
.steps_bar ul li.done span, .steps_bar ul li.current_prev span { background:#646464; }
.steps_bar ul li.current { color:#fff; background-color:#b70a06; }
.steps_bar ul li.current span { background:#b70a06; }
.steps_bar ul li.last { background-position:100% -180px; background-color:transparent; }
.steps_bar ul li.last span { background:#f1f1f1; }
.steps_bar ul li.last.current { background-position:100% -240px; }
.steps_bar ul li.last.current span { background:#b70a06; }
背景切片(PNG):

最終效果:

實際項目中用 JavaScript 切換 class 即可驅動狀態:當前步給 current,它的前一個給 current_prev,更早的全部給 done。有一個特例——當用戶停在第一步時,只需給第一個 li 加 current,不需要 current_prev。
帶邊框的版本之所以多一層 span,是因為箭頭背景要壓在 li 上、而上下框線需要作用在內層,兩者職責分離後才不會互相遮擋。最後一項 last 單獨去掉背景圖,避免右側露出多餘箭頭。