如何將css導覽功能表點擊過後變為背景圖片?

來源:互聯網
上載者:User
現在是滑鼠移到菜單上後,背景顏色改變,滑鼠移開或點擊後迴歸原色,現在是如何? 點擊後的底色就是滑鼠移到菜單上的底色,並且點擊另一個菜單的時候 前一個菜單的底色迴歸原色。

----------------css 部分------------------

<style>/*下拉式功能表樣式*/#div_center { width:100%; height:33px;  margin-left: auto;margin-right:auto;}  /*定義總體寬度、高度;background:003399; 控制背景顏色,置中對齊*/ #nav {line-height: 33px; list-style-type: none; }         /*控制一級菜單行高;上邊距5px;*/   #nav a { display: block; width: 80px; text-align:center; font-size:14px; font:"宋體"; font-weight: bold;     margin-left:10px;} /*一級菜單連結總體樣式:每個菜單的寬,置中對齊,文字大小*/ #nav a:link  {color:#000;text-decoration:none;margin:0;}     /* 未訪問的連結 */   #nav a:visited  {color:#000;text-decoration:none;margin:0;}    /* 已訪問的顏色 */  #nav a:hover {color:#fff;text-decoration:none;}                /* 滑鼠在連結上 */#nav li {float: left; margin-right:15px;}                   /* 一級菜靠左對齊 */ #nav li a:hover{background:url(images/1.jpg)}     /* 滑鼠在一級菜單上改變其背景色 */ #nav li:hover ul {left: auto;}#nav li.sfhover ul {left: auto;}#content {clear: left;}</style>

-----------css結束-------------

------------菜單內容-----------

<div><div id=div_center>                    <UL id=nav>                      <LI><A href="index.asp">首頁</A></LI>    <LI><a href="about.asp">學校簡介</a></LI>    <LI><A href="js.asp">教師風采</A> </LI>    <LI><A href="xs.asp">優秀學生</A> </LI>    <LI><A href="zp.asp">作品展廳</A> </LI>    <LI><A href="xc.asp">學校相簿</A> </LI>    <LI><A href="ly.asp">線上留言</A> </LI>  </UL>    </div></div>

-----------菜單內容結束--------

<html xmlns="http://www.w3.org/1999/xhtml"><head><title>選項卡菜單</title><style type="text/css">.bg{background:url(MenuLine.gif) repeat; height:30px; width:328px; line-height:30px}ul{list-style-type:none; margin:0; padding:0; font-size:14px}ul li{float:left; width:82px; text-align:center}.mouseon{background:url(Menu.gif) no-repeat; font-weight:bold; color:#f00}.mouseout{font-weight:normal}#content0,#content1{width:326px!important; width:328px; height:200px; border:1px solid #dcefe1}h2{margin:0; padding:0}</style><script language="javascript">function Tab(m,n){    var menu=document.getElementById('menu'+m).getElementsByTagName('li');    var list=document.getElementById('content'+m).getElementsByTagName('div');    for(var i=0;i<menu.length;i++)    {        menu[i].className=i==n?"mouseon":"mouseout";        list[i].style.display=i==n?"block":"none";    }}</script><body><div id="menu0" class="bg">    <ul>        <li class="mouseon" onMouseOver="Tab(0,0)">選項1</li>        <li class="mouseout" onMouseOver="Tab(0,1)">選項2</li>        <li class="mouseout" onMouseOver="Tab(0,2)">選項3</li>        <li class="mouseout" onMouseOver="Tab(0,3)">選項4</li>    </ul></div><div id="content0">    <div style="display:block">        <h2>帝王槌</h2><br/>        立劍賞月意惆悵,袖飾刀,衣披霜,傲視霧丸,徒手戰扶桑.<br />問津終尋帝王陵,黑影沒,屍滿崗,惟見逆鯪露寒光.  <br />鬚髮蒼,氣軒昂,三尺銀狼,破風動八方.  <br />依身緊握噬魂槍,飲虎血,豪萬丈.惟有千年我故鄉!    </div>    <div style="display:none">        <h2>玉女槍法</h2><br/>        曾經有個夢想:馳騁江湖,快意恩仇。<br />曾經有份願望:千裡追兇,十步濺血。<br />曾經有腔豪情:奇功蓋世,名冠武林。<br />曾經有種期盼:燭影搖紅,衣袖添香。    </div>    <div style="display:none">        <h2>黑沙剛體</h2><br/>        趙客縵胡纓,吳鉤霜雪明。銀鞍照白馬,颯遝如流星。十步殺一人,千裡不留行。事了拂衣去,深藏身與名。 閑過信陵飲,脫劍膝前橫。將炙啖朱亥,持觴勸侯嬴。 三杯吐然諾,五嶽倒為輕。眼花耳熱後,意氣素霓生。救趙揮金錘,邯鄲先震驚。千秋二壯士,烜赫大梁城。縱死俠骨香,不慚世上英。誰能書閣下,白首太玄經。    </div>    <div style="display:none">        <h2>不羈浪人槍</h2><br/>        素手相牽,斜輝入眼帘,一輪逍遙自在間,醉了山水閑。<br />沙漠綠水漣,魚遊淺底,明眸一水天。<br />愛在村友相談,開心點點,笑語連連,率性夜無眠。<br />月在西邊,風亂星寒,輾轉醇香舊事,蛾兒曼舞燈前。    </div></div><p><div id="menu1" class="bg">    <ul>        <li class="mouseon" onMouseOver="Tab(1,0)">選項5</li>        <li class="mouseout" onMouseOver="Tab(1,1)">選項6</li>        <li class="mouseout" onMouseOver="Tab(1,2)">選項7</li>        <li class="mouseout" onMouseOver="Tab(1,3)">選項8</li>    </ul></div><div id="content1">    <div style="display:block">        <h2>幹將</h2><br/>    幹將者,吳人也;莫邪,幹將之妻也。幹將作劍,金鐵之精不流,於是幹將夫妻,乃斷髮剪爪,投於爐中,金鐵乃濡,遂以成劍,陽曰幹將,陰曰莫邪。     </div>    <div style="display:none">        <h2>龍淵</h2><br/>        “何謂龍淵、太阿、工布?”答曰:“欲知龍淵,觀其狀,如登高山,臨深淵;欲知太阿,觀其(紋),巍巍翼翼,如流水之波;欲知工布,(紋)從文起,至脊而止,如珠不可衽,文若流水不絕。”    </div>    <div style="display:none">        <h2>湛盧</h2><br/>        歐冶子所鑄五大名劍為三大二小。其大者有湛盧、純鈞、勝邪;其小者有魚腸、世闕。    </div>    <div style="display:none">        <h2>軒轅劍</h2><br/>        軒轅采首山之銅,鑄劍,以天之古字題名。    </div></div></body></html>
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.