-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
319 lines (301 loc) · 9.49 KB
/
Copy pathindex.html
File metadata and controls
319 lines (301 loc) · 9.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TH - CSS Only Multilevel Dropdown</title>
<style type="text/css">
/***reset default styling***/
.nav,
.nav ul{
list-style-type:none;
margin:0;
padding:0;
}
.nav a {
text-decoration:none;
}
/*CUSTOMIZATION*/
/*i have split the code to have the width/height/color separate from the rest of the code*/
/*COLORS*/
/*here are some default colors, funky colors used for distinctive visibility*/
/*i hope that you can handle colors customization on your own :p*/
.nav {
background:yellow;
}
.nav a {
background:#9C3;
color:#000;
}
.nav ul {
background:red; /*top link persistent background color*/
}
.nav a.main {
background:transparent; /*so that the top link persistent background works*/
}
.nav ul a.main {
background:yellow;
}
.nav a.main:hover {
background:orange;
}
.nav .sub ul a {
background:#CC6;
}
.nav .sub ul a.main {
background:yellow;
}
.nav .sub ul a.main:hover {
background:orange;
}
.nav a:hover,
.nav a:focus,
.nav a:active{
background:orange;
}
.nav .sub li a:hover,
.nav .sub li a:focus,
.nav .sub li a:active{
background:#C93;
}
/*WIDTH (!IMPORTANT)*/
/*change each width value below, else the dropdown will stop working (:hover will still work in modern browsers because of the opera fix)*/
/*set the link width here*/
.nav .link,
.nav a {
width:9em; /*same as width*/
}
.nav ul li {
/*force ie8 to float-drop*/
max-width:9em; /*same as width*/
}
/*set the sublink left shift width here (same as width)*/
.nav ul ul {
/*move the sublinks to the side, so they dont overlap*/
left:9em; /*same as width*/
}
.nav li.reversed ul { /*reverse the direction of sublinks for the last dropdown*/
left:auto;
right:9em; /*same as width*/
}
/*add the negative value of "width - 1px" here (because css can't do math)*/
/*or (width - 0.063em) where 0.063em is 1px on 16px base size*/
.nav a {
/*makes the links very thin, so that the sublinks can hide inside the main link*/
/*!IMPORTANT: if you want a width of 9em, then you will have to change the value below to 8.937em (because: 9 - 0.063 = 8.973)*/
margin-right:-8.937em; /*make this width - 1px*//*or width - 0.063em (0.063 = 1px)*/
}
/*<customized width and positioning>*/
/*ONE*/
.nav .link.one {
margin-right:20px;
}
.nav .link.one,
.nav .one a {
width:11em;
}
.nav .one ul li {
max-width:11em;
}
.nav .one ul ul {
left:11em;
}
.nav .one a {
margin-right:-10.937em; /*11 - 0.063 = 10.937em (0.063 = 1px)*/
}
/*TWO*/
.nav .link.two {
margin-right:20px;
}
.nav .link.two,
.nav .two a {
width:3em;
}
.nav .two ul li {
max-width:3em;
}
.nav .two ul ul {
left:3em;
}
.nav .two a {
margin-right:-2.937em; /*3 - 0.063 = 2.937em (0.063 = 1px)*/
}
/*THREE*/
.nav .link.three {
margin-right:2px;
}
.nav .link.three,
.nav .three a {
width:9em;
}
.nav .three ul li {
max-width:9em;
}
.nav li.reversed.three ul { /*this is because its reversed*/
right:9em; /*same as width*/
}
.nav .three a {
margin-right:-8.937em;
}
/*</customized width and positioning>*/
/*HEIGHT*/
.nav {
height:1.563em; /*you could remove this and clear the float differently, but to me this makes the most sense*/
}
.nav a {
padding:.2em 0; /*apply padding to links, to vertically center them, be careful with horizontal padding in IE5, correct width must be maintained*/
}
.nav a.main {
height:1.563em; /*needs to be the same as the persistent background trick and so that the sublevels are properly aligned*/
line-height:1.563em; /*not really necessary, but in this specific case it vertically centers the main link text*/
overflow:hidden; /*making it more bulletproof*/
padding:0; /*remove the padding that was applied above*/
}
.nav ul {
padding-top:1.563em; /*persistent background trick*/
margin-top:-1.563em; /*persistent background trick*/
}
.nav ul ul {
position:relative; /*so that it can be moved top/left*/
top:-1.563em; /*this is the sole reason why the main links must have a fixed height*/
}
/*Dropper Dropdown*/
/*supports up to 4 sub-levels in IE5-7, more can be added*/
/*modern browsers already support any amount of sublevels*/
/*made by Timo Huovinen*/
.nav li {
float:left; /*fixes several IE related bugs, and allows for clearing*/
}
.nav ul {
float:left; /*necessary for float drop*/
}
.nav ul li {
clear:left; /*must clear the floated list item inside sublist*/
}
.nav a {
position:relative; /*needs to have a position, to be above the rest*/
display:block;
}
.nav a.main {
float:left; /*necessary for float drop*/
margin-top:10000px; /*bring the links back into view*/
}
.nav .link,
.nav .sub {
margin-top:-10000px; /*hide the links and their containers, opera has low upper limits*/
}
.nav ul {
margin-bottom:-5000px; /*avoid any interaction between the sub's, can be any large size*/
}
/*the main trick, removes the negative right-margin and causes float drop*/
.nav a:hover,
.nav a:focus,
.nav a:active{
margin-right:0;
}
/*OPERA fix*/
.nav ul:hover {
clear:left; /*fix for opera sublinks flickering on :hover*/
}
/*background no longer needed*/
.nav ul ul {
background:transparent;
}
/*IE5-6 + 7 bug fixes*/
.nav .sub {
width:100%;
}
/*empty rule to fix occassional IE6 tabbing bug, one of the weirdest bug's i have seen.
it seems that this indexes the links together as one? does not happen for everyone, but im leaving it just in case.*/
a, a:hover, a:active, a:focus {}
</style>
<!--I would also suggest adding some javascript to delay the closing of the sublinks, just to make it even better-->
</head>
<body>
<a href="https://github.com/thlib/css-dropdown-menu-example/">Source repository</a>
<ul class="nav">
<li class="link one">
<a class="main" href="#">Main</a>
<ul>
<li><a href="#1">test1</a></li>
<li><a href="#2">test2</a></li>
<li class="sub"><a class="main" href="#3">main 1 »</a>
<ul>
<li><a href="#subtest1">sub test 1</a></li>
<li><a href="#subtest2">sub test 2</a></li>
<li><a href="#subtest3">sub test 3</a></li>
<li><a href="#subtest4">sub test 4</a></li>
<li><a href="#subtest5">sub test 5</a></li>
<li><a href="#subtest6">sub test 6</a></li>
</ul>
</li>
<li class="sub"><a class="main" href="#4">main 2 »</a>
<ul>
<li><a href="#subtest1">sub test 1</a></li>
<li><a href="#subtest2">sub test 2</a></li>
<li><a href="#subtest3">sub test 3</a></li>
<li><a href="#subtest4">sub test 4</a></li>
<li><a href="#subtest5">sub test 5</a></li>
<li><a href="#subtest6">sub test 6</a></li>
</ul>
</li>
<li><a href="#5">test5</a></li>
<li><a href="#6">test6</a></li>
<li><a href="#7">long text link showing what happens</a></li>
<li><a href="#8">test8</a></li>
<li class="sub"><a class="main" href="#9">Everything is possible</a>
<ul>
<li><a href="#subtest1">sub test 1</a></li>
<li><a href="#subtest2">sub test 2</a></li>
<li><a href="#subtest3">sub test 3</a></li>
<li><a href="#subtest5">sub test 5</a></li>
<li><a href="#subtest6">sub test 6</a></li>
</ul>
</li>
</ul>
</li>
<li class="link two">
<a class="main" href="#">Main</a>
<ul>
<li><a href="#1">test1</a></li>
<li><a href="#2">test2</a></li>
<li><a href="#3">test3</a></li>
<li><a href="#4">test4</a></li>
<li><a href="#5">test5</a></li>
<li><a href="#6">test6</a></li>
<li><a href="#7">test7</a></li>
</ul>
</li>
<li class="link reversed three">
<a class="main" href="#">Main</a>
<ul>
<li><a href="#1">test1</a></li>
<li><a href="#2">test2</a></li>
<li><a href="#3">test3</a></li>
<li class="sub"><a class="main" href="#4">test4 »</a>
<ul>
<li><a href="#subtest1">sub test 1</a></li>
<li><a href="#subtest2">sub test 2</a></li>
<li><a href="#subtest3">sub test 3</a></li>
<li><a href="#subtest4">sub test 4</a></li>
<li><a href="#subtest5">sub test 5</a></li>
<li><a href="#subtest6">sub test 6</a></li>
</ul>
</li>
<li><a href="#5">test5</a></li>
<li><a href="#6">test6</a></li>
<li class="sub"><a class="main" href="#7">test7 »</a>
<ul>
<li><a href="#subtest1">sub2 test 1</a></li>
<li><a href="#subtest2">sub2 test 2</a></li>
<li><a href="#subtest3">sub2 test 3</a></li>
<li><a href="#subtest4">sub2 test 4</a></li>
<li><a href="#subtest5">sub2 test 5</a></li>
<li><a href="#subtest6">sub2 test 6</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<a href="https://github.com/thlib/css-dropdown-menu-example/">Source repository</a>
</body>
</html>