Menu
- Started
- Last post
- 3 Responses
- epigraph
I need to make a menu that starts as a main set of categories, and when one is selected a sub menu of categories pops up to the right, and from that another sub pops up to the right and so on.
farm4.static.flickr.com/3079/258...
what's the best way to do this? Transitions are nice but not necessary. If someone can at least tell me what to google I would appreciate it =)
- andrewwwahlin0
http://ajwahlin.com/2009/02/23/s…
You can change the CSS to move the drop downs around how you want them.
- I'm taking that page down, code posted below.andrewwwahlin
- andrewwwahlin0
CSS
_—-/—-/—-/—-/—-/
* html #menuv ul li{float:left;height:1%;}
* html #menuv ul li a{height:1%;}
#menuv
{
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333333;
text-align:left;
font-weight:bold;
}
#menuv a
{
width: 60px;
display:block;
padding-top: 5px;
padding-bottom: 1px;
white-space:nowrap;
color:#333333;
}
#menuv a, #menuv a:visited
{
color:#333333;
text-decoration:none;
}
#menuv a.parent, #menuv a.parent:hover
{
background-position: right center;
background-repeat: no-repeat;
}
#menuv a:hover
{
color: #000000;
}
#menuv li
{
list-style-type:none;
}
#menuv ul li
{
position:relative;
}
#menuv li ul
{
position: absolute;
width: 60px;
top: 20px;
left:0px;
display: none;
background-color:#EDEDED;
}
div#menuv ul, #menuv ul ul, div#menuv ul ul ul
{
margin:0;
padding:0;
width: 60px;
}
div#menuv ul ul, div#menuv ul ul ul, div#menuv ul li:hover ul ul, div#menuv ul li:hover ul ul ul
{
display: none;
}
div#menuv ul li:hover ul, div#menuv ul ul li:hover ul, div#menuv ul ul ul li:hover ul
{
display: block;
}_—-/—-/—-/—-/—-/
HTML (makes the link)
_—-/—-/—-/—-/—-/
<div id=”menuv-container”>
<div id=”menuv”>
<ul>
<li><a href=”LINK”>Link</a> </li>
</ul>
<ul>
<li><a href=”LINK”>Link</a> </li>
<ul>
<li><a href=”SUBLINK”>SubLink</a></li>
</ul>
</ul>
</div>
</div>_—-/—-/—-/—-/—-/
insert into the head
_—-/—-/—-/—-/—-/
<!–[if lt IE 7]>
<style type=”text/css” media=”screen”>
body{behavior:url(csshover.htc...
</style>
<![endif]–>_—-/—-/—-/—-/—-/
csshover.htc (the section above will link to this if it is needed)
_—-/—-/—-/—-/—-/
<attach event=”ondocumentready” handler=”parseStylesheets” />
<script>
/**
* Whatever:hover - V1.41.050927 - hover & active
* ————————————————————
* (c) 2005 - Peter Nederlof
* Peterned - http://www.xs4all.nl/~peterned/
* License - http://creativecommons.org/licen…
*
* Whatever:hover is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* Whatever:hover is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Credits and thanks to:
* Arnoud Berendsen, Martin Reurings, Robert Hanson
*
* howto: body { behavior:url(”csshover.htc”); }
* ————————————————————
*/var csshoverReg = /(^|\s)(([^a]([^ ]+)?)|(a([^#.][^ ]+)+)):(hover|active)/i,
currentSheet, doc = window.document, hoverEvents = [], activators = {
onhover:{on:’onmouseover’, off:’onmouseout’},
onactive:{on:’onmousedown’, off:’onmouseup’}
}function parseStylesheets() {
if(!/MSIE (5|6)/.test(navigator.userAgent... return;
window.attachEvent(’onunload’, unhookHoverEvents);
var sheets = doc.styleSheets, l = sheets.length;
for(var i=0; i<l; i++)
parseStylesheet(sheets[i]);
}
function parseStylesheet(sheet) {
if(sheet.imports) {
try {
var imports = sheet.imports, l = imports.length;
for(var i=0; i<l; i++) parseStylesheet(sheet.imports[i]);
} catch(securityException){}
}try {
var rules = (currentSheet = sheet).rules, l = rules.length;
for(var j=0; j<l; j++) parseCSSRule(rules[j]);
} catch(securityException){}
}function parseCSSRule(rule) {
var select = rule.selectorText, style = rule.style.cssText;
if(!csshoverReg.test(select) || !style) return;var pseudo = select.replace(/[^:]+:([a-z-]+).*/i, ‘on$1′);
var newSelect = select.replace(/(\.([a-z0-9_-]+):[a-z]+)|(:[a-z]+)/gi, ‘.$2′ + pseudo);
var className = (/\.([a-z0-9_-]*on(hover|active))/i).exec(newSelect)[1];
var affected = select.replace(/:(hover|active).*$/, ”);
var elements = getElementsBySelect(affected);
if(elements.length == 0) return;currentSheet.addRule(newSelect, style);
for(var i=0; i<elements.length; i++)
new HoverElement(elements[i], className, activators[pseudo]);
}function HoverElement(node, className, events) {
if(!node.hovers) node.hovers = {};
if(node.hovers[className]) return;
node.hovers[className] = true;
hookHoverEvent(node, events.on, function() { node.className += ‘ ‘ + className; });
hookHoverEvent(node, events.off, function() { node.className = node.className.replace(new RegExp(’\\s+’+className, ‘g’),”); });
}
function hookHoverEvent(node, type, handler) {
node.attachEvent(type, handler);
hoverEvents[hoverEvents.length] = {
node:node, type:type, handler:handler
};
}function unhookHoverEvents() {
for(var e,i=0; i<hoverEvents.length; i++) {
e = hoverEvents[i];
e.node.detachEvent(e.type, e.handler);
}
}function getElementsBySelect(rule) {
var parts, nodes = [doc];
parts = rule.split(’ ‘);
for(var i=0; i<parts.length; i++) {
nodes = getSelectedNodes(parts[i], nodes);
} return nodes;
}
function getSelectedNodes(select, elements) {
var result, node, nodes = [];
var identify = (/\#([a-z0-9_-]+)/i).exec(select);
if(identify) return [doc.getElementById(identify[1])];var classname = (/\.([a-z0-9_-]+)/i).exec(select);
var tagName = select.replace(/(\.|\#|\:)[a-z0-9_-]+/i, ”);
var classReg = classname? new RegExp(’\\b’ + classname[1] + ‘\\b’):false;
for(var i=0; i<elements.length; i++) {
result = tagName? elements[i].all.tags(tagName):elements[i].all;
for(var j=0; j<result.length; j++) {
node = result[j];
if(classReg && !classReg.test(node.className)) continue;
nodes[nodes.length] = node;
}
} return nodes;
}
</script>
_—-/—-/—-/—-/—-/