下面這段 CSS 示範了如何為連結(a 標籤)設定不同狀態的樣式,並在滑鼠移過(hover)與點擊(active)時加上背景圖,做出滑過就浮現紋理背景的特效。
.cast a:link
{
text-decoration:none;
color:#333333;
}
.cast a:visited {
color: #333333;
text-decoration: none;
}
.cast a:hover {
color: #b97a4f;
text-decoration: none;
background:url(/images/slide.gif) repeat-x;
}
.cast a:active {
color: #b97a4f;
text-decoration: none;
background:url(/images/slide.gif) repeat-x;
}
這裡透過 a:link、a:visited、a:hover、a:active 四種連結狀態分別定義樣式:正常與已造訪狀態保持沉穩的深灰色且無下劃線;而當滑鼠移過或點擊時,文字轉為暖棕色,並鋪上一張水平重複的背景圖 slide.gif,營造出滑過即亮的視覺反饋。
你可以依需求替換背景圖與配色,讓連結在互動時更具引導性。