轻量纯css多级下拉菜单,很实用的

今天有网友请教纯css多级下拉菜单的问题,所以我就写了一个,很实用,供大家参考。不必测试ie6,肯定不行,ie6死期将至,我不做它的兼容调试。

代码中还没有添加注释,不过不难理解。注释稍后添加。

以下是代码:

  1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
5 <title>无标题文档</title>
6 <style type="text/css">
7 body {
8 font-family:"宋体";
9 font-size:12px;
10 }
11 .menu {
12 height:30px;
13 background:#e6e6e6;
14 margin-left:10px;
15 }
16 .menu a {
17 text-decoration:none;
18 }
19 ul {
20 margin:0;
21 padding:0;
22 }
23 .menu li {
24 list-style:none;
25 float:left;
26 width:90px;
27 overflow:visible;
28 cursor:pointer;
29 }
30 ul.level0 {
31 height:30px;
32 overflow:visible;
33 }
34 ul.level1, ul.level2, ul.level3 {
35 width:90px;
36 display:none;
37 }
38 ul.level2, ul.level3 {
39 margin:-28px 0 0 90px;
40 }
41 ul.level0 > li {
42 height:30px;
43 line-height:30px;
44 text-align:center;
45 background:#999;
46 }
47 ul.level1 > li, ul.level2 > li, ul.level3 > li {
48 height:28px;
49 line-height:28px;
50 background:#bbb;
51 }
52 ul.level0 > li:hover {
53 background:#ccc;
54 }
55 ul.level1 > li:hover, ul.level2 > li:hover, ul.level3 > li:hover {
56 background:#ddd;
57 }
58 ul.level0 > li.imyeah:hover > ul, ul.level1 > li.imyeah:hover > ul, ul.level2 > li.imyeah:hover > ul, ul.level3 > li.imyeah:hover > ul {
59 display:block;
60 }
61 </style>
62 </head>
63
64 <body>
65 <div class="menu">
66 <ul class="level0">
67 <li class="imyeah"> <a href="#">immenu0</a>
68 <ul class="level1">
69 <li> <a href="#">imdropmenu00</a> </li>
70 <li class="imyeah"> <a href="#">imdropmenu01</a>
71 <ul class="level2">
72 <li class="imyeah"> <a href="#">imdropmenu010</a>
73 <ul class="level3">
74 <li> <a href="#">imdropmenu0100</a> </li>
75 <li> <a href="#">imdropmenu0101</a> </li>
76 </ul>
77 </li>
78 <li> <a href="#">imdropmenu011</a> </li>
79 <li> <a href="#">imdropmenu012</a> </li>
80 </ul>
81 </li>
82 <li> <a href="#">imdropmenu02</a> </li>
83 <li> <a href="#">imdropmenu03</a> </li>
84 <li> <a href="#">imdropmenu04</a> </li>
85 </ul>
86 </li>
87 <li class="imyeah"> <a href="#" class="top_link">immenu1</a>
88 <ul class="level1">
89 <li class="imyeah"> <a href="#">imdropmenu10</a>
90 <ul class="level2">
91 <li> <a href="#">imdropmenu100</a> </li>
92 <li class="imyeah"> <a href="#">imdropmenu101</a>
93 <ul class="level3">
94 <li> <a href="#">imdropmenu1010</a> </li>
95 <li> <a href="#">imdropmenu1011</a> </li>
96 </ul>
97 </li>
98 <li> <a href="#">imdropmenu102</a> </li>
99 </ul>
100 </li>
101 <li> <a href="#">imdropmenu11</a> </li>
102 <li> <a href="#">imdropmenu12</a> </li>
103 <li> <a href="#">imdropmenu13</a> </li>
104 <li> <a href="#">imdropmenu14</a> </li>
105 <li> <a href="#">imdropmenu15</a> </li>
106 </ul>
107 </li>
108 <li class="imyeah"> <a href="#" class="top_link">immenu2</a>
109 <ul class="level1">
110 <li> <a href="#">imdropmenu20</a> </li>
111 <li> <a href="#">imdropmenu21</a> </li>
112 </ul>
113 </li>
114 <li class="imyeah"> <a href="#" class="top_link">immenu3</a>
115 <ul class="level1">
116 <li> <a href="#">imdropmenu30</a> </li>
117 <li> <a href="#">imdropmenu31</a> </li>
118 <li> <a href="#">imdropmenu32</a> </li>
119 </ul>
120 </li>
121 <li> <a href="#" class="top_link">immenu4</a> </li>
122 </ul>
123 </div>
124 </body>
125 </html>

效果图如下:

posted @ 2011-12-23 16:36  ferrinweb  阅读(904)  评论(1编辑  收藏  举报