鼠標懸浮時菜單項向上移動成藍底白字,點擊之后底部會有藍條表示當前選中項。
頁面代碼,菜單的每一項都是一個 div ,其中包括一個 ul 用來放置顯示文字等,另一個 div 則是底部的藍條,需要給第一項和最后一項設置不同的 class ,樣式需要用到:
樣式,主要就是每個菜單項的左右邊框的設置以及 ul 和 li 的位置設置:
* { padding: 0; margin: 0; } body { background-color: #fffff3; font: 12px/1.6em Helvetica, Arial, sans-serif; } ul,li{ list-style: none; } #nav { text-align: center; height: 50px; font-size: 10px; line-height: 30px; background-color: #F0E6DB; margin-bottom: 10px; } .navItem { cursor: pointer; position: relative; float: left; width: 100px; height: 50px; font-size: 15px; border-right: 2px solid rgb(255,255,255); border-left: 2px solid rgb(255,255,255); overflow: hidden; font-weight:bold; } .indexNavItem { border-left: 4px solid rgb(255,255,255); margin-left: 10px; } .lastNavItem { border-right: 4px solid rgb(255,255,255); } .logoutNavItem { float: right; width: 120px; margin-right: 10px; border-left: 4px solid rgb(255,255,255); } .navUl { position: relative; height: 100px; width: 100%; border-bottom: 5px solid rgb(2,159,212); } .navUl li { height: 50px; line-height: 50px; } .highlighter { position: absolute; bottom: 0; height: 5px; width: 100%; } .selectedNav { background-color: #029FD4; } .hoverLi { background-color: #029FD4; color: #ffffff; }
接下來就是給菜單編寫懸浮和單擊事件的 js 代碼了,懸浮時將 ul 上移 li 的高度,鼠標移開后再恢復,點擊之后就是給藍條的 div 添加樣式即可:
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com