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

所属分类: 网页制作 / CSS 阅读数: 426
收藏 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入门教程:计算CSS盒模型宽和高

 出处:当我们布局一个网页的时候,经常会遇到这样的一种情况,那就是最终网页成型的宽度或是高度会超出我们预先的计算,其实就就是所谓的CSS的盒模型造成的。 #test{margin:10px;padding:10px;width:100px;height:100px;}
收藏 0 赞 0 分享

在IE流览器中正确显示PNG透明图片

  png图片有很好的品质。阴影效果也不会有杂边,很流畅。如果插入网页的话可以给网站内容增色不少!更重要的是在不增加图片容量大小的情况下提高了页面的图片的质量。对于有复杂背景,如:在有颜色过度背景上插入不规则边框的图片带来极大很便利!   但目前IE中对于插入
收藏 0 赞 0 分享

CSS教程:DIV底部放置文字

  css对文字的布局上没有靠容器底部对齐的参数,目前使用的一个不错的方法也比较好.就是用position属性来解决,看下面的代码,用position的相对和绝对定位功能也轻松的实现了,文字靠近div低部对齐,并且靠近的距离还可以精确到像素,自己可以调节,是不是很不错呢?
收藏 0 赞 0 分享

如何用CSS让文字居于div的底部

  这个问题是别人提出的,因为css对文字的布局上没有靠容器底部对齐的参数,(或许有但是我没有发现)不过目前我使用的一个不错的方法也比较好.就是用position属性来解决,看下面的代码,我用position的相对和绝对定位功能也轻松的实现了,文字靠近div低部对齐,并且靠近
收藏 0 赞 0 分享

从A页面连接到B页面后并直接把B页面的隐藏层显示

  这个效果实现的是,在B页面里有两个层,一个显示层,我们暂定名c层,一个是隐藏层,我们暂定名d层,单独进B页面的时候,c层显示,d层隐藏,然而从A页面连接到B页面的时候,则是让d层显示,c层隐藏,我觉得这个效果对网页设计者以后会有很大帮助,现在把代码发出来,
收藏 0 赞 0 分享

CSS样式表定义标签li前面样式

定义LI前面的小点样式 view plaincopy to clipboardprint? 语法: list-style-type : disc | circle | square | decimal | lower-roman | upper-roman | lowe
收藏 0 赞 0 分享

符合标准的div css制作的弹出菜单

本文介绍了五款符合标准的div css制作的弹出菜单,而且不含有js的. NO.1最基本的:二级dropdown弹出菜单 <!DOCTYPE html PUB
收藏 0 赞 0 分享

CSS实现在文章每段后面加入带连接的隐藏文字

代码主要理解3个参数:createElement、createTextNode、appendChild。这3个js参数分别是创建元素、创建字符、追加节点。代码原理:循环页面段落标签<p>,创建连接元素<a>,创建要显示的连接字符,用SetAttribute
收藏 0 赞 0 分享

CSS:浏览器特定选择器介绍

当你想在一个浏览器里改变样式而不像在其他浏览器中改变时,这些选择器很有用。 IE6以下 *html{} IE 7 以下 *:first-child html {} * html {} 只对IE 7 *:first-child html {} 只对IE 7
收藏 0 赞 0 分享

WEB标准学习,认识两种网页声明的含义

即网页标准推出来以后,我们时常会看到两种不同的网页的声明,一个是Dhtml,一个是Xhtml。如下所示: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "ht
收藏 0 赞 0 分享
查看更多