用CSS實現下拉式功能表的多種方法_經驗交流

來源:互聯網
上載者:User
橫向下拉式功能表
<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <meta http-equiv="Content-Language" content="zh-CN" /> <title>橫向下拉式功能表</title> <style type="text/css"> <!-- * {margin:0;padding:0;border:0;} body { font-family: arial, 宋體, serif; font-size:12px; } #nav { height: 24px; list-style-type: none; padding-left:200px; line-height:24px;overflow:hidden;background:#999; } #nav a { display: block; width: 80px; text-align:center; } #nav a:link { color:#EEE; text-decoration:none; } #nav a:visited { color:#EEE;text-decoration:none; } #nav a:hover { color:#FFF;text-decoration:none;font-weight:bold;background:#CCC; } #nav li { float: left; width: 80px; } #nav li ul { line-height: 24px; list-style-type: none; text-align:left; left: -999px; width: 520px; //注意,這裡一定要設定寬度; position: absolute; background:#CCC; } #nav li ul li{ float: left;width: 80px; //float就是子功能表橫向的關鍵,可以繼承父菜單而省略float } #nav li ul a{ display: block; width: 65px;text-align:left;padding-left:15px; } #nav li ul a:link { color:#F1F1F1; text-decoration:none; } #nav li ul a:visited { color:#F1F1F1;text-decoration:none; } #nav li ul a:hover { color:#FFF;text-decoration:none;font-weight:normal;background:#C00; } #nav li:hover ul { left:25%; } #nav li.sfhover ul { left:25%; } #content { clear: left; } --> </style> </head> <body> <ul id="nav"> <li>菜單一 <ul> <li>菜單一</li> <li>菜單一</li> <li>菜單一</li> <li>菜單一</li> <li>菜單一</li> <li>菜單一</li> </ul> </li> <li>菜單二 <ul> <li>菜單二</li> <li>菜單二</li> <li>菜單二</li> <li>菜單二</li> <li>菜單二</li> </ul> </li> <li>菜單三 <ul> <li>菜單三</li> <li>菜單三</li> <li>菜單三</li> <li>菜單三</li> <li>菜單三</li> </ul> </li> <li>菜單四 <ul> <li>菜單四</li> <li>菜單四</li> <li>菜單四</li> <li>菜單四</li> <li>菜單四</li> </ul> </li> <li>菜單五 <ul> <li>菜單五</li> <li>菜單五</li> <li>菜單五</li> <li>菜單五</li> <li>菜單五</li> </ul> </li> <li>菜單六 <ul> <li>菜單六</li> <li>菜單六</li> <li>菜單六</li> <li>菜單六</li> <li>菜單六</li> </ul> </li> </ul> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
CSS下拉導覽功能表效果
<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>CSS下拉式功能表示範</title> <style type="text/css"> <!-- *{margin:0;padding:0;border:0;} body { font-family: arial, 宋體, serif; font-size:12px; } #nav { line-height: 24px; list-style-type: none; background:#666; } #nav a { display: block; width: 80px; text-align:center; } #nav a:link { color:#666; text-decoration:none; } #nav a:visited { color:#666;text-decoration:none; } #nav a:hover { color:#FFF;text-decoration:none;font-weight:bold; } #nav li { float: left; width: 80px; background:#CCC; } #nav li a:hover{ background:#999; } #nav li ul { line-height: 27px; list-style-type: none;text-align:left; left: -999em; width: 180px; position: absolute; } #nav li ul li{ float: left; width: 180px; background: #F6F6F6; } #nav li ul a{ wedisplay: block; width: 156px;text-align:left;padding-left:24px; } #nav li ul a:link { color:#666; text-decoration:none; } #nav li ul a:visited { color:#666;text-decoration:none; } #nav li ul a:hover { color:#F3F3F3;text-decoration:none;font-weight:normal; background:#C00; } #nav li:hover ul { left: auto; } #nav li.sfhover ul { left: auto; } #content { clear: left; } --> </style> </head> <body> <ul id="nav"> <li>產品介紹 <ul> <li>產品一</li> <li>產品一</li> <li>產品一</li> <li>產品一</li> <li>產品一</li> <li>產品一</li> </ul> </li> <li>服務介紹 <ul> <li>服務二</li> <li>服務二</li> <li>服務二</li> <li>服務二服務二</li> <li>服務二服務二服務二</li> <li>服務二</li> </ul> </li> <li>成功案例 <ul> <li>案例三</li> <li>案例</li> <li>案例三案例三</li> <li>案例三案例三案例三</li> </ul> </li> <li>關於我們 <ul> <li>我們四</li> <li>我們四</li> <li>我們四</li> <li>我們四111</li> </ul> </li> <li>線上示範 <ul> <li>示範</li> <li>示範</li> <li>示範</li> <li>示範示範示範</li> <li>示範示範示範</li> <li>示範示範</li> <li>示範示範示範</li> <li>示範示範示範示範示範</li> </ul> </li> <li>聯絡我們 <ul> <li>聯絡聯絡聯絡聯絡聯絡</li> <li>聯絡聯絡聯絡</li> <li>聯絡</li> <li>聯絡聯絡</li> <li>聯絡聯絡</li> <li>聯絡聯絡聯絡</li> <li>聯絡聯絡聯絡</li> </ul> </li> </ul> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
CSS水平下拉式功能表
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CSS Menu - Horizontal</title> <style type="text/css"> <!-- @import"dhtml-horiz.css"; --> body { margin: 0; padding: 30px; background: #FFF; color: #666; } h1 { font: bold 16px Arial, Helvetica, sans-serif; } p { font: 11px Arial, Helvetica, sans-serif; } a { color: #900; text-decoration: none; } a:hover { background: #900; color: #FFF; } /*CSS Code for Menu Begin:*/ /* Root = Horizontal, Secondary = Vertical */ ul#navmenu { margin: 0; border: 0 none; padding: 0; width: 500px; /*For KHTML*/ list-style: none; height: 24px; } ul#navmenu li { margin: 0; border: 0 none; padding: 0; float: left; /*For Gecko*/ display: inline; list-style: none; position: relative; height: 24px; } ul#navmenu ul { margin: 0; border: 0 none; padding: 0; width: 160px; list-style: none; display: none; position: absolute; top: 24px; left: 0; } ul#navmenu ul li { float: none; /*For Gecko*/ display: block !important; display: inline; /*For IE*/ } /* Root Menu */ ul#navmenu a { border: 1px solid #FFF; border-right-color: #CCC; border-bottom-color: #CCC; padding: 0 6px; float: none !important; /*For Opera*/ float: left; /*For IE*/ display: block; background: #EEE; color: #666; font: bold 10px/22px Verdana, Arial, Helvetica, sans-serif; text-decoration: none; height: auto !important; height: 1%; /*For IE*/ } /* Root Menu Hover Persistence */ ul#navmenu a:hover, ul#navmenu li:hover a, ul#navmenu li.iehover a { background: #CCC; color: #FFF; } /* 2nd Menu */ ul#navmenu li:hover li a, ul#navmenu li.iehover li a { float: none; background: #EEE; color: #666; } /* 2nd Menu Hover Persistence */ ul#navmenu li:hover li a:hover, ul#navmenu li:hover li:hover a, ul#navmenu li.iehover li a:hover, ul#navmenu li.iehover li.iehover a { background: #CCC; color: #FFF; } /* 3rd Menu */ ul#navmenu li:hover li:hover li a, ul#navmenu li.iehover li.iehover li a { background: #EEE; color: #666; } /* 3rd Menu Hover Persistence */ ul#navmenu li:hover li:hover li a:hover, ul#navmenu li:hover li:hover li:hover a, ul#navmenu li.iehover li.iehover li a:hover, ul#navmenu li.iehover li.iehover li.iehover a { background: #CCC; color: #FFF; } /* 4th Menu */ ul#navmenu li:hover li:hover li:hover li a, ul#navmenu li.iehover li.iehover li.iehover li a { background: #EEE; color: #666; } /* 4th Menu Hover */ ul#navmenu li:hover li:hover li:hover li a:hover, ul#navmenu li.iehover li.iehover li.iehover li a:hover { background: #CCC; color: #FFF; } ul#navmenu ul ul, ul#navmenu ul ul ul { display: none; position: absolute; top: 0; left: 160px; } /* Do Not Move - Must Come Before display:block for Gecko */ ul#navmenu li:hover ul ul, ul#navmenu li:hover ul ul ul, ul#navmenu li.iehover ul ul, ul#navmenu li.iehover ul ul ul { display: none; } ul#navmenu li:hover ul, ul#navmenu ul li:hover ul, ul#navmenu ul ul li:hover ul, ul#navmenu li.iehover ul, ul#navmenu ul li.iehover ul, ul#navmenu ul ul li.iehover ul { display: block; } </style> </head> <body> <h1>CSS Menu - Horizontal</h1> <hr /> <ul id="navmenu"> <li>Blog</li> <li>Work + <ul> <li>Websites + <ul> <li>qrayg</li> <li>qArcade</li> <li>qLoM</li> <li>qDT</li> </ul> </li> <li>Pen and Ink</li> <li>Free Interfaces</li> </ul> </li> <li>Learn + <ul> <li>Fireworks + <ul> <li>aquaButton</li> <li>aquaButton2</li> <li>waterDrop</li> <li>lightFX</li> <li>lightFX2</li> </ul> </li> <li>CSS + <ul> <li>footerStick</li> <li>spriteNav</li> <li>@import</li> </ul> </li> </ul> </li> <li>Info</li> <li>Contact</li> </ul> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
CSS垂直下拉式功能表
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CSS Menu - Vertical</title> <style type="text/css"> body { margin: 0; padding: 30px; background: #FFF; color: #666; } h1 { font: bold 16px Arial, Helvetica, sans-serif; } p { font: 11px Arial, Helvetica, sans-serif; } a { color: #900; text-decoration: none; } a:hover { background: #900; color: #FFF; } /*CSS Code for Menu Begin:*/ /* Root = Vertical, Secondary = Vertical */ ul#navmenu, ul#navmenu li, ul#navmenu ul { margin: 0; border: 0 none; padding: 0; width: 160px; /*For KHTML*/ list-style: none; } ul#navmenu li { display: block !important; /*For GOOD browsers*/ display: inline; /*For IE*/ position: relative; } /* Root Menu */ ul#navmenu a { border: 1px solid #FFF; border-right-color: #CCC; border-bottom-color: #CCC; padding: 0 6px; display: block; background: #EEE; color: #666; font: bold 10px/22px Verdana, Arial, Helvetica, sans-serif; text-decoration: none; height: auto !important; height: 1%; /*For IE*/ } /* Root Menu Hover Persistence */ ul#navmenu a:hover, ul#navmenu li:hover a, ul#navmenu li.iehover a { background: #CCC; color: #FFF; } /* 2nd Menu */ ul#navmenu li:hover li a, ul#navmenu li.iehover li a { background: #EEE; color: #666; } /* 2nd Menu Hover Persistence */ ul#navmenu li:hover li a:hover, ul#navmenu li:hover li:hover a, ul#navmenu li.iehover li a:hover, ul#navmenu li.iehover li.iehover a { background: #CCC; color: #FFF; } /* 3rd Menu */ ul#navmenu li:hover li:hover li a, ul#navmenu li.iehover li.iehover li a { background: #EEE; color: #666; } /* 3rd Menu Hover Persistence */ ul#navmenu li:hover li:hover li a:hover, ul#navmenu li:hover li:hover li:hover a, ul#navmenu li.iehover li.iehover li a:hover, ul#navmenu li.iehover li.iehover li.iehover a { background: #CCC; color: #FFF; } /* 4th Menu */ ul#navmenu li:hover li:hover li:hover li a, ul#navmenu li.iehover li.iehover li.iehover li a { background: #EEE; color: #666; } /* 4th Menu Hover */ ul#navmenu li:hover li:hover li:hover li a:hover, ul#navmenu li.iehover li.iehover li.iehover li a:hover { background: #CCC; color: #FFF; } ul#navmenu ul, ul#navmenu ul ul, ul#navmenu ul ul ul { display: none; position: absolute; top: 0; left: 160px; } /* Do Not Move - Must Come Before display:block for Gecko */ ul#navmenu li:hover ul ul, ul#navmenu li:hover ul ul ul, ul#navmenu li.iehover ul ul, ul#navmenu li.iehover ul ul ul { display: none; } ul#navmenu li:hover ul, ul#navmenu ul li:hover ul, ul#navmenu ul ul li:hover ul, ul#navmenu li.iehover ul, ul#navmenu ul li.iehover ul, ul#navmenu ul ul li.iehover ul { display: block; } </style> </head> <body> <h1>CSS Menu - Vertical</h1> <hr /> <ul id="navmenu"> <li>Blog</li> <li>Work + <ul> <li>Websites + <ul> <li>qrayg</li> <li>qArcade</li> <li>qLoM</li> <li>qDT</li> </ul> </li> <li>Pen and Ink</li> <li>Free Interfaces</li> </ul> </li> <li>Learn + <ul> <li>Fireworks + <ul> <li>aquaButton</li> <li>aquaButton2</li> <li>waterDrop</li> <li>lightFX</li> <li>lightFX2</li> </ul> </li> <li>CSS + <ul> <li>footerStick</li> <li>spriteNav</li> <li>@import</li> </ul> </li> </ul> </li> <li>Info</li> <li>Contact</li> </ul> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
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> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <meta name="Keywords" content="bilingual menu,中英文雙語菜單" /> <meta http-equiv="Description" content="完全用CSS實現的中英文雙語導覽功能表" /> <meta content="all" name="robots" /> <meta name="author" content="forestgan" /> <meta name="copyright" content="http://www.forest53.com" /> <title>完全用CSS實現的中英文雙語導覽功能表</title> <style type="text/css"> a{ color: #FFFF99; text-decoration: none; } a:hover{ color: #FFFFFF; text-decoration: underline; } #nav{ padding: 10px 10px 0; font-size: 12px; font-weight: bold; margin: 1em 0 0; list-style:none; } #nav li{ float: left; margin-right: 1px; } .bi{ position: relative; z-index: 0; } .bi:hover{ z-index: 99; } .bi:hover span{ visibility: visible; top: 0; left: 0; cursor: pointer; } .bi span{ position: absolute; left: -999em; visibility: hidden; } #nav li a,.bi:hover span{ line-height: 20px; text-decoration: none; background: #DDDDDD; color: #666666; display: block; width: 80px; text-align: center; } #nav li a:hover,.bi:hover span{ color: #FFFFFF; background: #DC4E1B; } .bi:hover span{ padding-top: 2px; } #navbar{ background: #DC4E1B; height: 8px; overflow: hidden; clear: both; } </style> <link href="../css/main.css" rel="stylesheet" type="text/css" /> </head> <body> <ul id="nav"> <li>Home<span>首 頁</span></li> <li>Blog<span>日誌</span></li> <li>guestbook<span>留言本</span></li> <li>Pickbar<span>精品吧</span></li> <li>fansir<span>樊SIR</span></li> </ul> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
  • 相關文章

    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.