打造最美CSS多级下拉横向导航菜单代码

所属分类: 网页制作 / CSS 阅读数: 432
收藏 0 赞 0 分享

本文实例为大家分享了纯CSS实现多级下拉横向导航菜单代码,供大家参考,具体内容如下

先看看效果图:

实现代码:

CSS代码:

CSS Code复制内容到剪贴板
  1. <style type="text/css">   
  2. /* for this demo only */  
  3. #backgroundHolder { width:750pxheight:500pxpadding-top:10pxmargin:0 auto; }   
  4. /* ---------------------------------------------------------------------------- */  
  5. /* default styling */  
  6. .nav, .nav ul { list-style-type:nonemargin:0; padding:0; }   
  7. .nav a { text-decoration:none; }   
  8. .nav { font-familyarialsans-seriffont-size:12pxwidth:650pxmargin:0 auto; }   
  9. /* style the links */  
  10. .nav a { background:url(ulmulti3/box.gif) no-repeat rightright center; }   
  11. .nav a.top { background:url(ulmulti3/box.gif) no-repeat rightright top; }   
  12. .nav a.top2 { background:url(ulmulti3/box2.gif) no-repeat rightright top; }   
  13. .nav a.bottombottom { background:url(ulmulti3/box.gif) no-repeat rightright bottombottom; }   
  14. .rightright ul ul a { background:url(ulmulti3/box3.gif) no-repeat rightright center; }   
  15. .rightright ul ul a.top2 { background:url(ulmulti3/box3.gif) no-repeat rightright top; }   
  16. .rightright ul ul a.bottombottom { background:url(ulmulti3/box3.gif) no-repeat rightright bottombottom; }   
  17. /* style the <b> element so that is does not affect the size of the link */  
  18. .nav a b { color:#ffffont-weight:normaldisplay:blockpadding:5px 10px 5px 15px; }   
  19. .nav .fly .main b { backgroundtransparent url(ulmulti3/arrow.gif) no-repeat 117px 9px; }   
  20. .nav .down b { backgroundtransparent url(ulmulti3/arrow2.gif) no-repeat 115px 11px; }   
  21. .nav .rightright ul b { text-align:rightright; }   
  22. .nav .rightright ul ul b { padding5px 15px 5px 10px; }   
  23. .nav .rightright ul .main b { backgroundtransparent url(ulmulti3/arrow3.gif) no-repeat 15px 9pxtext-align:rightright; }   
  24. .nav .rightright ul ul .main b { backgroundtransparent url(ulmulti3/arrow3.gif) no-repeat 5px 9pxtext-align:rightright; }   
  25. /* HEIGHT */  
  26. .nav ul ul { top:-24px; } /* position the top of the flyout first sub menus */  
  27. .nav ul ul ul { top:-25px; } /* position the top of the flyout second and third sub menus */  
  28. .nav ul.two { top:-40px; } /* position the top of the flyout sub menus with previous text on two lines */  
  29. /* WIDTH change this WITH CARE to suit your requirements */  
  30.     
  31. /*set the link width here*/  
  32. .nav .drop, .nav a { width:130px; }   
  33. .nav ul li { max-width:130px; } /* fix for IE8 */  
  34. /* set the left flyout position here */  
  35. .nav ul ul { left:130px; }   
  36. /* set the right flyout position here */  
  37. .nav li.rightright ul ul { left:autorightright:120px; }   
  38. .nav li.rightright ul ul ul { left:autorightright:130px; }   
  39. /* make this WIDTH - 1px */ /* or WIDTH - 0.063em if using em sizing */  
  40. .nav a { margin-right:-129px; }   
  41. /* ---------------------------------------------------------------------------- */  
  42.     
  43. /* DO NOT CHANGE ANYTHING BELOW */  
  44. .nav li { float:left; } /* fixes IE bugs, and allows for clearing */  
  45. .nav ul { float:leftposition:relativez-index:20; } /* necessary for float drop and to stack the <ul>s */  
  46. .nav ul li { clear:left; } /* must clear the floated list item inside sublist */  
  47. .nav a { position:relativedisplay:block; } /* needs to have a position, to be above the rest */  
  48. .nav a.main { float:left/* necessary for float drop */ margin-top:10000px; } /* bring the top level links back into view */  
  49. .nav .drop, .nav .fly { margin-top:-10000px; } /* hide the sub links and their containers, opera has low upper limits */  
  50. .nav ul { margin-bottom:-5000px; } /* avoid any interaction between the subs, can be any large size */  
  51. /* The bit that does ALL the work to bring the sub menus into view */  
  52.     
  53. .nav a:hover, .nav a:focus, .nav a:active { margin-right:0; z-index:10; outline:0; }   
  54. .nav a:hover b, .nav a:focus b, .nav a:active b { color:#000cursor:pointer; } /* this is for keyboard tabbing color change */  
  55. /* OPERA fix */  
  56. .nav ul:hover, .nav ul ul:hover { clear:left; } /* to stop intermittent sub link :hover problems */  
  57.     
  58. /* ---------------------------------------------------------------------------- */  
  59. </style>   
  60. <!--[if lte IE 7]>   
  61. <style type="text/css">   
  62. /* bug fixes for IE7 and lower - DO NOT CHANGE */  
  63. .nav .fly {width:99%;} /* make each flyout 99% of the prevous level */  
  64. a:active {} /* requires a blank style for :active to stop it being buggy */  
  65. </style>   
  66.   

html代码:

XML/HTML Code复制内容到剪贴板
  1. <body>  
  2. <div id="backgroundHolder">  
  3.   <ul class="nav">  
  4.     <li class="drop"><a class="main top" href="#url"><b>Home</b></a></li>  
  5.     <li class="drop"><a class="main down top" href="#url"><b>Equipment</b></a>  
  6.       <ul>  
  7.         <li class="fly"><a class="main" href="#url"><b>Cameras</b></a>  
  8.           <ul>  
  9.             <li><a class="top2" href="#url"><b>Film Type</b></a></li>  
  10.             <li><a href="#url"><b>Compact</b></a></li>  
  11.             <li><a href="#url"><b>Polaroid</b></a></li>  
  12.             <li><a href="#url"><b>Digital</b></a></li>  
  13.             <li class="fly"><a class="main" href="#url"><b>Digital SLR</b></a>  
  14.               <ul>  
  15.                 <li><a class="top2" href="#url"><b>Canon</b></a></li>  
  16.                 <li><a href="#url"><b>Nikon</b></a></li>  
  17.                 <li><a href="#url"><b>Panasonic</b></a></li>  
  18.                 <li><a class="bottom" href="#url"><b>Kodak</b></a></li>  
  19.               </ul>  
  20.             </li>  
  21.             <li><a class="bottom" href="#url"><b>Second Hand</b></a></li>  
  22.           </ul>  
  23.         </li>  
  24.         <li class="fly"><a class="main" href="#url"><b>Video Cameras & Accessories</b></a>  
  25.           <ul class="two">  
  26.             <li class="fly"><a class="main top2" href="#url"><b>Latest Models</b></a>  
  27.               <ul>  
  28.                 <li><a class="top2" href="#url"><b>Nikon</b></a></li>  
  29.                 <li><a href="#url"><b>Panasonic</b></a></li>  
  30.                 <li><a href="#url"><b>Canon</b></a></li>  
  31.                 <li><a href="#url"><b>Pentax</b></a></li>  
  32.                 <li><a class="bottom" href="#url"><b>Minolta</b></a></li>  
  33.               </ul>  
  34.             </li>  
  35.             <li><a href="#url"><b>Special Offers</b></a></li>  
  36.             <li><a class="bottom" href="#url"><b>Professional</b></a></li>  
  37.           </ul>  
  38.         </li>  
  39.         <li class="fly"><a class="main" href="#url"><b>Lenses</b></a>  
  40.           <ul>  
  41.             <li class="fly"><a class="main top2" href="#url"><b>Digital</b></a>  
  42.               <ul>  
  43.                 <li><a class="top2" href="#url"><b>Standard</b></a></li>  
  44.                 <li><a href="#url"><b>Telephoto</b></a></li>  
  45.                 <li><a href="#url"><b>Wide Angle</b></a></li>  
  46.                 <li class="fly"><a class="main" href="#url"><b>Zoom</b></a>  
  47.                   <ul>  
  48.                     <li><a class="top2" href="#url"><b>Nikon</b></a></li>  
  49.                     <li><a href="#url"><b>Pentax</b></a></li>  
  50.                     <li><a href="#url"><b>Minolta</b></a></li>  
  51.                     <li><a class="bottom" href="#url"><b>Panasonic</b></a></li>  
  52.                   </ul>  
  53.                 </li>  
  54.                 <li class="fly"><a class="main" href="#url"><b>Zoom with Macro</b></a>  
  55.                   <ul>  
  56.                     <li><a class="top2" href="#url"><b>Panasonic</b></a></li>  
  57.                     <li><a href="#url"><b>Minolta</b></a></li>  
  58.                     <li><a href="#url"><b>Pentax</b></a></li>  
  59.                     <li><a href="#url"><b>Canon</b></a></li>  
  60.                     <li><a class="bottom" href="#url"><b>Nikon</b></a></li>  
  61.                   </ul>  
  62.                 </li>  
  63.                 <li><a href="#url"><b>Fisheye</b></a></li>  
  64.                 <li><a class="bottom" href="#url"><b>x2 converters</b></a></li>  
  65.               </ul>  
  66.             </li>  
  67.             <li class="fly"><a class="main" href="#url"><b>Standard SLR</b></a>  
  68.               <ul>  
  69.                 <li><a class="top2" href="#url"><b>Canon</b></a></li>  
  70.                 <li><a href="#url"
更多精彩内容其他人还在看

Opera中国的WEB标准课程

网页制作Webjx文章简介:在这篇文章里,我要向大家介绍我和其他很多人花费数月时间开发的一个课程——Web标准课程,该课程旨在向大家提供Web设计和开发的坚实基础,无论读者是谁,此教程完全免费、可访问,并且不需要预备知识。当然,我主要还
收藏 0 赞 0 分享

CSS样式表渐进增强的基本概念

网页制作Webjx文章简介:如果你挠着头想弄清楚优雅降级和渐进增强的区别,我告诉你,这是视角问题。优雅降级和渐进增强都考虑网站在各种设备的各种浏览器上如何良好运转。两者区别的关键在于它们各自关注的焦点,以及这种关注对工作流程的影响
收藏 0 赞 0 分享

简单介绍Web Developer插件制作网页

网页制作Webjx文章简介:Firefox浏览器是一个良好支持W3C标准的开放源代码的浏览器,拥有Linux/Windows/Mac版本。因为Firefox浏览器良好支持W3C标准,所以使用Firefox来调试网页是非常好的。 Firefox浏览器是
收藏 0 赞 0 分享

CSS布局带来的巨大影响:CSS display属性值

网页制作Webjx文章简介:网页元素应用上那些与表格相关的display属性值后,能够模仿出与表格相同的特性。我将会在该文中给大家演示这种方法给CSS布局带来的巨大影响。 应原书编辑要求,先在文章顶部给出链接:《Everything You
收藏 0 赞 0 分享

用div css模拟表格对角线

这只是探讨一种CSS模拟表格对角线的用法,实际在工作中可能觉得这样做有点小题大作,这不是本主题讨论的重点。如果对此深以为然的朋友,请一笑过之 首先声明: 这只是探讨一种CSS模拟表格对角线的
收藏 0 赞 0 分享

IE Firefox在css中的差别 (部分)

1、单位问题 问题:任何距离的数值ie可以不加单位,ff必须要求写单位(0除外) 解决:写全单位如padding:0px; 2、水平居中 问题:div里的内容,ie默认为center,而ff默认left 解决:mairgin:0px auto; 3、高度问题
收藏 0 赞 0 分享

不用js可以实现信息提示效果

[code] <style> body { font:verdena; font-size:14px; color:#000 } h1{ font:verdena; font-size:22px; color:#000 } h2{ font:verdena;
收藏 0 赞 0 分享

CSS解决未知高度的垂直水平居中自适应问题

今天有人问起,晚上试着写出来,供参考; 以下代码兼容主流浏览器IE6、IE7、Firefox、Opera。 从最简单的开始………… 一、如何让一个DIV水平居中? 这个简单不作过多说明! [code] <st
收藏 0 赞 0 分享

CSS cursor 属性 -- 鼠标指针样式效果

取值: [ [<uri> ,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize |
收藏 0 赞 0 分享

css 简单区别ie6,ie7,firefox的写法

同一样式里可以这样 [code] margin:17px; FF +margin:17px; IE6 IE7 _margin:17px; IE6 [/code] 按这个顺序,刚好区分开三个浏览器
收藏 0 赞 0 分享
查看更多