實際上,這裡的圖片在正常使用時完全可以用CSS代碼來定義。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>使用圖片交換技術製作CSS滑鼠移至上方菜單</title> <style type="text/css"> div#spritemenu { height: 50px; width: 400px; font-size: 9px; background-image: url(yun_qi_img/spritemenu.gif); overflow: hidden; } div#spritemenu ul li { display: inline; margin: 0px; padding: 0px; } div#spritemenu ul li a { display: block; position:relative; height: 50px; } div#spritemenu ul li a:hover { background-image: url(yun_qi_img/spritemenu.gif); } div#spritemenu ul { margin: 0px; padding: 0px; list-style-type:none; height: 50px; } div#spritemenu span { display: none; } div#spritemenu li.buttonA a {top: 0px; left: 0px; width: 80px; background-position: 0px 0px;} div#spritemenu li.buttonB a {top: -50px; left: 82px; width: 64px; background-position: -82px 0px;} div#spritemenu li.buttonC a {top: -100px; left: 148px; width: 76px; background-position: -148px 0px;} div#spritemenu li.buttonD a {top: -150px; left: 226px; width: 70px; background-position: -226px 0px;} div#spritemenu li.buttonE a {top: -200px; left: 298px; width: 102px; background-position: -298px 0px;} div#spritemenu li.buttonA a:hover {background-position: 0px -50px;} div#spritemenu li.buttonB a:hover {background-position: -82px -50px;} div#spritemenu li.buttonC a:hover {background-position: -148px -50px;} div#spritemenu li.buttonD a:hover {background-position: -226px -50px;} div#spritemenu li.buttonE a:hover {background-position: -298px -50px;} </style> </head> <body> <div id="spritemenu"> <ul> <li class="buttonA"><span>Home</span></li> <li class="buttonB"><span>About</span></li> <li class="buttonC"><span>Contact</span></li> <li class="buttonD"><span>Forum</span></li> <li class="buttonE"><span>Guestbook</span></li> </ul> </div> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]