呵呵为什么又来一个破解,为什么是淘宝菜单,因为taobao上面的菜单,可以说是中国第一个大型网站采用css做的滑动门菜单,二来
滑动门有一弱点就是会产生选中链接的虚线线框偏移,而淘宝的菜单是没有虚线框的,哈哈至于怎么做到的我们会在下面分析:

好了长话段说我们先打开taobao的首页看看找到如下代码:

  1. <ul id="ChannelMenuItems">
  2.       <li id="MenuHome"><a href="http://www.taobao.com/index.php?from=top" target="_top"><span>首页</span></a></li>
  3.       <li id="MenuDigital"><a href="http://www.taobao.com/vertical/digital/index.php?from=top" target="_top"><span>数码通讯</span></a></li>
  4.       <li id="MenuLady"><a href="http://www.taobao.com/vertical/lady/index.php?from=top" target="_top"><span>女人</span></a></li>
  5.       <li id="MenuLife"><a href="http://www.taobao.com/vertical/life/index.php?from=top" target="_top"><span>家居</span></a></li>
  6.       <li id="MenuPet"><a href="http://www.taobao.com/vertical/pet/index.php?from=top" target="_top"><span>宠物</span></a></li>
  7.       <li id="MenuMan"><a href="http://www.taobao.com/vertical/man/index.php?from=top" target="_top"><span>男人</span></a></li>
  8.       <li id="MenuSports"><a href="http://www.taobao.com/vertical/sports/index.php?from=top" target="_top"><span>运动</span></a></li>
  9.       <li id="MenuGame"><a href="http://www.taobao.com/vertical/game/index.php?from=top" target="_top"><span>游戏</span></a></li>
  10.       <li id="MenuCulture"><a href="http://www.taobao.com/vertical/culture/index.php?from=top" target="_top"><span>书籍音像</span></a></li>
  11.       <li id="MenuHongkong"><a href="http://www.taobao.com/vertical/hkstreet/index.php?from=top" target="_top"><span>香港街</span></a></li>
  12.       <li id="MenuMall"><a href="http://www.taobao.com/vertical/mall/index.php?from=top" target="_top"><span>淘宝商城</span></a></li>
  13.     </ul>

很标准的滑动门菜单结构,至于真正的滑动门菜单技术我们这里不详细介绍,如果你不是很了解的话,可以去看《CSS中的滑动门技术》,我们在查找一下菜单的css

  1. #Head #ChannelMenuItems{
  2.     width:640px;
  3.     height:30px;
  4.     margin:0 auto;
  5.     /*attach promotion event background images here*/
  6. }
  7. #Head #ChannelMenuItems li{
  8.     float:left;
  9.     height:30px;
  10.     margin-right:1px;
  11.     /*attach promotion event background images here*/
  12. }
  13. #Head #ChannelMenuItems a{
  14.     display:block;
  15.     float:left;
  16.     height:30px;
  17.     background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_home_left.gif) left top no-repeat;
  18.     text-decoration:none;
  19. }
  20. #Head #ChannelMenuItems a span{
  21.     display:block;
  22.     float:left;
  23.     height:30px;
  24.     padding:11px 11px 0;
  25.     background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_home_right.gif) right top no-repeat;
  26.     text-align:center;
  27.     color:#000;
  28.     font-style:normal;
  29.     cursor:hand;
  30.     /*IE 5.x Crack at the bottom of this file*/
  31. }
  32.  
  33. /*IE5.x Hack Rules*/
  34. #head #channelmenuitems a span{
  35.     cursor: pointer;
  36.     height: 19px;
  37.     voice-family: "\"}\"";
  38.     voice-family: inherit;
  39. }
  40.  
  41. #head #channelmenuitems li{
  42.     float: left;
  43.     height: 30px;
  44.     margin-right: 1px; /*attach promotion event background images here*/
  45. }
  46.  
  47.  
  48. body.CurHome ul#ChannelMenuItems li#MenuHome a{background:#FF9000 url(http://pics.taobao.com/2k5/sys/common/header/chl_home_left_act.gif) left top no-repeat;}
  49. body.CurHome ul#ChannelMenuItems li#MenuHome a span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_home_right_act.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  50.  
  51. body.CurDigital ul#ChannelMenuItems li#MenuDigital a{background:#99A2B1 url(http://pics.taobao.com/2k5/sys/common/header/chl_digital_left_act.gif) left top no-repeat;}
  52. body.CurDigital ul#ChannelMenuItems li#MenuDigital a span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_digital_right_act.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  53.  
  54. body.CurLady ul#ChannelMenuItems li#MenuLady a{background:#E1569A url(http://pics.taobao.com/2k5/sys/common/header/chl_lady_left_act.gif) left top no-repeat;}
  55. body.CurLady ul#ChannelMenuItems li#MenuLady a span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_lady_right_act.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  56.  
  57. body.CurMan ul#ChannelMenuItems li#MenuMan a{background:#3672AE url(http://pics.taobao.com/2k5/sys/common/header/chl_man_left_act.gif) left top no-repeat;}
  58. body.CurMan ul#ChannelMenuItems li#MenuMan a span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_man_right_act.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  59.  
  60. body.CurLife ul#ChannelMenuItems li#MenuLife a{background:#EC9307 url(http://pics.taobao.com/2k5/sys/common/header/chl_life_left_act.gif) left top no-repeat;}
  61. body.CurLife ul#ChannelMenuItems li#MenuLife a span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_life_right_act.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  62.  
  63. body.CurCulture ul#ChannelMenuItems li#MenuCulture a{background:#1E998B url(http://pics.taobao.com/2k5/sys/common/header/chl_culture_left_act4.gif) left top no-repeat;}
  64. body.CurCulture ul#ChannelMenuItems li#MenuCulture a span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_culture_right_act3.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  65.  
  66. body.CurSports ul#ChannelMenuItems li#MenuSports a{background:#E30303 url(http://pics.taobao.com/bao/album/chl/sports/chl_sports_left_act_060601.gif) left top no-repeat;}
  67. body.CurSports ul#ChannelMenuItems li#MenuSports a span{background:transparent url(http://pics.taobao.com/bao/album/chl/sports/chl_sports_right_act_060601.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  68.  
  69. body.CurGame ul#ChannelMenuItems li#MenuGame a{background:#C34B26 url(http://pics.taobao.com/2k5/sys/common/header/chl_game_left_act.gif) left top no-repeat;}
  70. body.CurGame ul#ChannelMenuItems li#MenuGame a span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_game_right_act.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  71.  
  72. body.CurCollection ul#ChannelMenuItems li#MenuCollection a{background:#88605F url(http://pics.taobao.com/2k5/sys/common/header/chl_collection_left_act2.gif) left top no-repeat;}
  73. body.CurCollection ul#ChannelMenuItems li#MenuCollection a span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_collection_right_act2.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  74.  
  75. body.CurHongkong ul#ChannelMenuItems li#MenuHongkong a{background:#965BB9 url(http://pics.taobao.com/2k5/sys/common/header/chl_hongkong_left_act2.gif) left top no-repeat;}
  76. body.CurHongkong ul#ChannelMenuItems li#MenuHongkong a span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_hongkong_right_act2.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  77.  
  78. body.CurMall ul#ChannelMenuItems li#MenuMall a{background:#A48752 url(http://pics.taobao.com/bao/album/sys/misc/chl_mall_left_act.gif) left top no-repeat;}
  79. body.CurMall ul#ChannelMenuItems li#MenuMall a span{background:transparent url(http://pics.taobao.com/bao/album/sys/misc/chl_mall_left_act_r.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  80.  
  81. body.CurPet ul#ChannelMenuItems li#MenuPet a{background:#86D500 url(http://pics.taobao.com/bao/album/sys/misc/chl_pet_left_act2.gif) left top no-repeat;}
  82. body.CurPet ul#ChannelMenuItems li#MenuPet a span{background:transparent url(http://pics.taobao.com/bao/album/sys/misc/chl_pet_right_act2.gif) right top no-repeat;font-weight:bold;color:#FFF;}
  83.  
  84.  
  85.  
  86.  
  87. /*Hover triggers*/
  88. #Head #ChannelMenuItems li#MenuHome a:hover{background:#FF9000 url(http://pics.taobao.com/2k5/sys/common/header/chl_home_left_act.gif) left top no-repeat;}
  89. #Head #ChannelMenuItems li#MenuHome a:hover span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_home_right_act.gif) right top no-repeat;color:#FFF;}
  90. #Head #ChannelMenuItems li#MenuDigital a:hover{background:#99A2B1 url(http://pics.taobao.com/2k5/sys/common/header/chl_digital_left_act.gif) left top no-repeat;}
  91. #Head #ChannelMenuItems li#MenuDigital a:hover span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_digital_right_act.gif) right top no-repeat;color:#FFF;}
  92. #Head #ChannelMenuItems li#MenuLady a:hover{background:#E1569A url(http://pics.taobao.com/2k5/sys/common/header/chl_lady_left_act.gif) left top no-repeat;}
  93. #Head #ChannelMenuItems li#MenuLady a:hover span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_lady_right_act.gif) right top no-repeat;color:#FFF;}
  94. #Head #ChannelMenuItems li#MenuMan a:hover{background:#3672AE url(http://pics.taobao.com/2k5/sys/common/header/chl_man_left_act.gif) left top no-repeat;}
  95. #Head #ChannelMenuItems li#MenuMan a:hover span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_man_right_act.gif) right top no-repeat;color:#FFF;}
  96. #Head #ChannelMenuItems li#MenuLife a:hover{background:#EC9307 url(http://pics.taobao.com/2k5/sys/common/header/chl_life_left_act.gif) left top no-repeat;}
  97. #Head #ChannelMenuItems li#MenuLife a:hover span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_life_right_act.gif) right top no-repeat;color:#FFF;}
  98. #Head #ChannelMenuItems li#MenuCulture a:hover{background:#1E998B url(http://pics.taobao.com/2k5/sys/common/header/chl_culture_left_act4.gif) left top no-repeat;}
  99. #Head #ChannelMenuItems li#MenuCulture a:hover span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_culture_right_act3.gif) right top no-repeat;color:#FFF;}
  100. #Head #ChannelMenuItems li#MenuSports a:hover{background:#E30303 url(http://pics.taobao.com/bao/album/chl/sports/chl_sports_left_act_060601.gif) left top no-repeat;}
  101. #Head #ChannelMenuItems li#MenuSports a:hover span{background:transparent url(http://pics.taobao.com/bao/album/chl/sports/chl_sports_right_act_060601.gif) right top no-repeat;color:#FFF;}
  102. #Head #ChannelMenuItems li#MenuGame a:hover{background:#C34B26 url(http://pics.taobao.com/2k5/sys/common/header/chl_game_left_act.gif) left top no-repeat;}
  103. #Head #ChannelMenuItems li#MenuGame a:hover span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_game_right_act.gif) right top no-repeat;color:#FFF;}
  104. #Head #ChannelMenuItems li#MenuCollection a:hover{background:#88605F url(http://pics.taobao.com/2k5/sys/common/header/chl_collection_left_act2.gif) left top no-repeat;}
  105. #Head #ChannelMenuItems li#MenuCollection a:hover span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_collection_right_act2.gif) right top no-repeat;color:#FFF;}
  106. #Head #ChannelMenuItems li#MenuHongkong a:hover{background:#965BB9 url(http://pics.taobao.com/2k5/sys/common/header/chl_hongkong_left_act2.gif) left top no-repeat;}
  107. #Head #ChannelMenuItems li#MenuHongkong a:hover span{background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_hongkong_right_act2.gif) right top no-repeat;color:#FFF;}
  108. #Head #ChannelMenuItems li#MenuMall a:hover{background:#965BB9 url(http://pics.taobao.com/bao/album/sys/misc/chl_mall_left_act.gif) left top no-repeat;}
  109. #Head #ChannelMenuItems li#MenuMall a:hover span{background:transparent url(http://pics.taobao.com/bao/album/sys/misc/chl_mall_left_act_r.gif) right top no-repeat;color:#FFF;}
  110. #Head #ChannelMenuItems li#MenuPet a:hover{background:#86D500 url(http://pics.taobao.com/bao/album/sys/misc/chl_pet_left_act2.gif) left top no-repeat;}
  111. #Head #ChannelMenuItems li#MenuPet a:hover span{background:transparent url(http://pics.taobao.com/bao/album/sys/misc/chl_pet_right_act2.gif) right top no-repeat;color:#FFF;}

上面就是我提取出来菜单的样式表,哈哈很多代码吧,我们仔细看看根本没有什么刻意特殊的代码在里面,看来用css特殊属性去除线框的可能性排除了,选中菜单链接以后没有虚线通常的做法使用javascript来实现,这个比较常见具体方法可以查看《去除链接虚线框》, 那我们再从新回到页面源代码查看,结果没有发现可疑代码。哪taobao到底是怎么做的呢,我们再回头看看上面的代码,发现在所有文字的两边多了一个标签,大家都知道,做滑动门菜单根本不用这个完全是可以实现,难道就因为的原因才没有虚线框的吗,那么我们把代码下载下来实验一下,吧去掉,看看什么效果,果然去掉的菜单除了虚线框不过虚线框还是不错,没有偏移,好那么我们就来看看这个是什么css属性,怎样起到这个作用的,看下面代码:

  1. #Head #ChannelMenuItems li{
  2.     float:left;
  3.     height:30px;
  4.     margin-right:1px;
  5.     /*attach promotion event background images here*/
  6.    }
  7.    #Head #ChannelMenuItems a{
  8.     display:block;
  9.     float:left;
  10.     height:30px;
  11.     background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_home_left.gif) left top no-repeat;
  12.      text-decoration:none;
  13.    }
  14.   #Head #ChannelMenuItems a span{
  15.     display:block;
  16.     float:left;
  17.     height:30px;
  18.     padding:11px 11px 0;
  19.     background:transparent url(http://pics.taobao.com/2k5/sys/common/header/chl_home_right.gif) right top no-repeat;
  20.     text-align:center;
  21.     color:#000;
  22.     font-style:normal;
  23.     cursor:hand;
  24.     /*IE 5.x Crack at the bottom of this file*/
  25.    }

传统我们做滑动门菜单通常是吧定义按钮的大小和边距定义在a上和li上,然后在a和li上定义不同的背景文件,最后组合制作成一个按钮,而在这段代码里面大家发现,li和a只定义了高度根本没有定义边距,而且只有a放了按钮左边的图像背景文件,li是空的,而真正定义按钮大小的是span,不仅定义了右边的背景,高度还有两边的边距,还有display:block;和cursor:hand;,哪到底为什么要这么做呢?好下面我们来做一个小实验:

  1. <a href="#"><span>www.d8in.com</span></a>

这段代码是没有定义的,但是采用了同样的结构就是嵌套最后里面是要链接的文字,大家发现虚线框是紧紧包裹在文字周围的,我们继续测试下面代码

  1. <style type="text/css">
  2.      span{
  3.          display: block;
  4.         height: 30px;
  5.      }
  6.      a{
  7.          display: block;
  8.         height: 30px;
  9.      }
  10.     </style>
  1. <a href="#"><span>www.d8in.com</span></a>

这段代码同时定义了a和span,display: block;和height: 30px;,发现鼠标放了连接上变成输入指针,但是链接依然刻意点击。
最后测试最终代码:


www.d8in.com

最后终结一淘宝菜单的制作原理;
1.用