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

所属分类: 网页制作 / CSS 阅读数: 479
收藏 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"
更多精彩内容其他人还在看

CSS配合JavaScript做酷的动态页面效果

  利用CSS配合JavaScript的可以做很多更酷的动态页面效果,在本教程的最后给大家简单介绍一下CSS配合JS的应用。首先,要搞清楚事件和动作的概念。在客户端脚本中,JavaScript 通过对事件进行响应来获得与用户的交互。例如,当用户单击一个按钮或者在某段文字上移动鼠标
收藏 0 赞 0 分享

WEB标准,Web前端开发工程师必备技术列表

  想要打造并拥有一流的Web产品开发团队,在团队成员基础能力上一定要下功夫。对于Web前端产品开发来说,仅仅掌握Web1.0时代简单的"网页套接"是完全不够的。我结合自己的团队配备,特此罗列了Web前端产品工程师所涉及的技能列表如下:   通过许多实际项目,
收藏 0 赞 0 分享

用CSS制作Alpha滤镜测试板

alpha滤镜给制作网页特效提供了较大的创作空间,但由于它控制参数较多,在实际应用时,为了确定一组合适的参数值,不得不反复调整修改,在编辑窗口和预览窗口来回倒腾,甚是麻烦,本文介绍了一种简单的方法。制作一个“Alpha滤镜参数测试板”,在测试板上输入参数
收藏 0 赞 0 分享

非常流行的所谓的气泡窗口

普通的Alt无法自定义风格,而Sweet Titles通过JS脚本与CSS的集合.自定义了这种伪Alt风格. 前一段时间非常流行的,就所谓的气泡窗口(鼠标移到链接处出现的). 我们这里实现的用的是Sweet Titles的插件.显示效果完全由CSS控制.. 先下载Sweet Ti
收藏 0 赞 0 分享

CSS教程:li和ul标签用法举例

LI代码的格式化: A).运用CSS格式化列表符: ul li{ list-style-type:none; } B).如果你想将列表符换成图像,则: ul li{ list-style-type:none; list-style-image: url(/blog/images/
收藏 0 赞 0 分享

CSS教程:CSS中的定位(position)

  使用CSS来定位页面内层的位置,一直是比较难以掌握的事情,很多时候,往往被绝对定位的元素,总是以浏览器的左上角为坐标原点,此时,如果浏览器的大小改变,被定义的层就会偏离设计想要的位置,让人很挠头。   其实,要想控制好层的绝对定位,只要理解CSS中关于定位
收藏 0 赞 0 分享

CSS教程:盒模型(BOX Model)

  如果想熟练掌握DIV和CSS的布局方法,首先要对盒模型有足够的了解。每个HTML元素都可以看作一个装了东西的盒子,盒子里面的内容到盒子的边框之间的距离即填充(padding),盒子本身有边框(border),而盒子边框外和其他盒子之间,还有边界(margin),如图1所示。
收藏 0 赞 0 分享

无延迟翻滚的图形与CSS混合风格按钮

  在一个具有图形背景的按钮中添加CSS风格的文本,这种建立按钮的方法结合了具有CSS翻滚(CSS rollover)标记的开发速度和效率,从而有效地提高按钮外表图像的三维效果。   相比于常规的图形按钮,这些图形/CSS混合按钮可易于建立和载入,因为你只需要为空白按钮外面
收藏 0 赞 0 分享

css里expression实现界面对象的批量控制

用过css样式我们就知道, 可以定义一批对象的class属性来指定同一个样式来统一界面. 但如何统一同类型的对象的事件? 比如:界面有无数个 <img src="**.jpg"> 如何实现鼠标经过此图片, 图片的src变成是**_over.jpg?
收藏 0 赞 0 分享

CSS教程:水平对齐(text-align)

  水平对齐(text-align),用以设定元素内文本的水平对齐方式。   1.语法   text-align具体参数如下: 语法:text-align:left|right|center|justify 说明:设定元素内文本的水平对齐方式。 参数:left:左
收藏 0 赞 0 分享
查看更多