Ask Experts Questions for FREE Help!
Answer   ||    Advanced Search

Ask your question or search...
International Sites: Nederlandse experts vragen
User Name 
Password 
Join   Forgot password? 

Home > Computers & Technology > Internet & the Web   »   Collapsing - Expanding Navigation List

Question
 
 
#1  
Old Apr 27, 2006, 09:22 AM
RickJ's Avatar
RickJ
Über Member
RickJ is offline
 
Join Date: Aug 2005
Location: The Bogs at Windover
Posts: 7,363
RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.
Collapsing - Expanding Navigation List

Check out the menu on the left here:
Welcome to K.Y.P.S.A.H. Pet Services! Keeping Your Pet Safe and Happy!

Click on one of the Items, and you'll see the list expand under it.

Can I do that without CSS? Yep, I confess: I don't know CSS. Whip me!
Can it be done with html?

Thanks!

Reply With Quote
 
     

Answers
 
 
Old Apr 28, 2006, 07:16 AM   #2  
Ultra Member
LTheobald is offline
 
LTheobald's Avatar
 
Join Date: Feb 2004
Location: Cambridge, UK
Posts: 1,047
LTheobald See this member's comment history on his/her Profile page.LTheobald See this member's comment history on his/her Profile page.
Call LTheobald via Skype™ Send a message via MSN to LTheobald
To put it simply - no. You'll need some basic CSS and possible some JavaScript. But don't worry Rick - It's easy! For now look here for some inspiration on what you can do:

Listamatic: one list, many options - Using CSS and a simple list to create radically different list options

Then when I get a second, I'll write you a navigation list and I'll keep it as simple and easy to maintain as possible. I will need your help though. I need you to write a HTML list. It will need to be in this format:
Code:
<ul>
    <li>First Level Item A</li>
        <ul>
            <li>Second Level Item A</li>
            <li>Second Level Item B</li>
            <li>Second Level Item C</li>
        </ul>
    <li>First Level Item A</li>
        <ul>
            <li>Second Level Item A</li>
            <li>Second Level Item B</li>
            <li>Second Level Item C</li>
        </ul>
    <li>First Level Item A</li>
        <ul>
            <li>Second Level Item A</li>
            <li>Second Level Item B</li>
            <li>Second Level Item C</li>
        </ul>
</ul>

Comments on this post
RickJ agrees: you da man! Thanks, LT, I'll start on some reading.
  Reply With Quote
 
     
 
 
Old Apr 28, 2006, 08:00 AM   #3  
Über Member
RickJ is offline
 
RickJ's Avatar
 
Join Date: Aug 2005
Location: The Bogs at Windover
Posts: 7,363
RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.
This is looking very familiar; like the trick you showed me for here.

Ok, step one, your above code, done, here:
Untitled Document
  Reply With Quote
 
     
 
 
Old May 2, 2006, 01:36 AM   #4  
Ultra Member
LTheobald is offline
 
LTheobald's Avatar
 
Join Date: Feb 2004
Location: Cambridge, UK
Posts: 1,047
LTheobald See this member's comment history on his/her Profile page.LTheobald See this member's comment history on his/her Profile page.
Call LTheobald via Skype™ Send a message via MSN to LTheobald
Rick,

Just to let you know I haven't forgotten you. I'm writing up a guide to how to do this at the moment. It's about 95% done and I'll finish it after work today.

Lee,
  Reply With Quote
 
     
 
 
Old May 2, 2006, 02:33 AM   #5  
Über Member
RickJ is offline
 
RickJ's Avatar
 
Join Date: Aug 2005
Location: The Bogs at Windover
Posts: 7,363
RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.
You're awesome, LT!!

Hey Google; pick up this: LTheobald is a Website Design Expert and all around great guy!
  Reply With Quote
 
     
 
 
Old May 2, 2006, 03:16 AM   #6  
Ultra Member
LTheobald is offline
 
LTheobald's Avatar
 
Join Date: Feb 2004
Location: Cambridge, UK
Posts: 1,047
LTheobald See this member's comment history on his/her Profile page.LTheobald See this member's comment history on his/her Profile page.
Call LTheobald via Skype™ Send a message via MSN to LTheobald
You haven't seen the code yet. I be might have just done an Arnold Rimmer (Red Drawf character) and just repeatedly written "I AM A FISH" for 20 pages :P

Also - not an expert. Still young, lots to learn but I'm always eager to help
  Reply With Quote
 
     
 
 
Old May 2, 2006, 03:23 AM   #7  
Über Member
RickJ is offline
 
RickJ's Avatar
 
Join Date: Aug 2005
Location: The Bogs at Windover
Posts: 7,363
RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.
LOL.

You've helped me before...and I've learned alot from reading your posts helping others.
  Reply With Quote
 
     
 
 
Old May 2, 2006, 01:07 PM   #8  
Ultra Member
LTheobald is offline
 
LTheobald's Avatar
 
Join Date: Feb 2004
Location: Cambridge, UK
Posts: 1,047
LTheobald See this member's comment history on his/her Profile page.LTheobald See this member's comment history on his/her Profile page.
Call LTheobald via Skype™ Send a message via MSN to LTheobald
Finally done writing this. I'll attach my test version on the page at the end so you can tinker with that if needs be. Just rename it from testpage.txt to testpage.html to see it in action.

OK. Sorry the reply took so long Rick. We had a 3 day weekend over here in the Uk and I didn't get a chance to get on my PC much. Well I'm on a train to work at the moment so I've got a good amount of time to write up a reply. The code below is similar to what I gave you last time in a way but it will hopefully be a little tidier. I'll also try and write it in a better to understand way. Hopefully...

The code is based on the Suckerfish Dropdown article from A List Apart.


The HTML

The best kind of HTML to use for a navigation bar or some kind is a list. After all, it's just a list of pages. So for this navigation we'll use unordered lists. This way we'll have some nice, clean HTML that should be standards complient and accessible regardless of browser type. So
1. to start off, create a basic web page with this in the body:

Code:
<ul>
    <li>Categories
        <ul>
            <li><a href="">Computing</a></li>
            <li><a href="">Geography</a></li>
            <li><a href="">History</a></li>
            <li><a href="">Science</a></li>
            <li><a href="">Sport</a></li>
        </ul>
    </li>
    <li>Members
        <ul>
            <li><a href="">LTheobald</a></li>
            <li><a href="">Rickj</a></li>
            <li><a href="">CurleyBen</a></li>
            <li><a href="">ScottGem</a></li>
            <li><a href="">Orange</a></li>
        </ul>
    </li>
    <li>Tools
        <ul>
            <li><a href="">Search</a></li>
            <li><a href="">Members List</a></li>
            <li><a href="">New Posts</a></li>
        </ul>
    </li>
</ul>
That will give you a 2 level list. It should look like a helper page for AMHD. Now we have the HTML, we want to use some CSS to make this list look more like a series of dropdowns. I'm afraid this is where the CSS comes in. To keep this example simple, we'll keep the CSS styles in HTML page with the code.

2. In the <head> section of the page, enter the following:

Code:
<style>
    ul {
        padding: 0px;
        margin: 0px;
        list-style: none;
        background-color: #53BF58;
        width: 10em;
    }
</style>
This first bit of CSS styles all lists on the page (the <ul> elements) to remove the indentation and bullet points. I've also added a width and some colour in there just to make things a little clearer. The example will now just look like lines of text one under the other. As we want a dropdown list we now have to hide the inner lists (holding the categories, member names and tools in this example). To do this,
3. add the following lines between the style tags under the existing ul {} part:

Code:
li ul {
    display: none;
    background-color: #86EF8A;
}
This bit of CSS means "For every list (ul) within a list item (li), set it's display to none (hide)". So this will hide all our inner lists. Yet again, a little colour added for clarity.


Now For The Magic

We now have our dropdown list all ready to code. So onto making the lists dropdown. There's two ways of doing this:
  1. Having the lists appear when the user hovers over a link
  2. Having the lists appear when the user clicks on a link
The code is pretty similar for either one. Now as the Suckerfish Dropdown article already handles what to do when hovering over links, I'll take what to do when the user clicks on the links. Before we can write the code itself we need to write two simple changes to the HTML & CSS we wrote earlier. First, the HTML change. We need to
4. change the root list tag (the very first <ul> tag from:

Code:
<ul>
to

Code:
<ul id="nav">
That will just give us a way of identifying our dropdown list. The CSS change adds a class that shows us which dropdown is currently active.
5. Add the following lines inbetween the style tags

Code:
li.active ul {
    display: block;
}
This code will set a list to be shown when it's parent's class is set to active. So for example if we set the Members <li> tag to have a class of active, the members list will be shown. Now it's time to write the code itself.
6. Inbetween the <head> tags for the page, enter the following:

Code:
<script language="JavaScript">
function hideAll() {
    var navList = document.getElementById("nav");
    for (var i=0; i<navList.childNodes.length; i++) {
        var node = navList.childNodes[i];
        if (node.tagName == "LI") {
            node.className = node.className.replace(new RegExp("\s?active", "i"), "");
        }
    }
}

window.onload = function () {
    var navList = document.getElementById("nav");
    for (var i=0; i<navList.childNodes.length; i++) {
        var node = navList.childNodes[i];
        if (node.tagName == "LI") {
            node.onclick = function() {
                hideAll();
                this.className += " active";
            }
        }
    }
}
</script>
There's two parts to this script. The first function, hideAll(), hides all the lists when shown. A call to this function will ensure that we only have one dropdown shown at a time. The second part sets up what happens when we click on a link.


And That's It

All done. Hopefully now you'll have a dropdown list that'll work in nearly all browsers. I've tested this in IE, Firefox and Opera and it looks just fine.

As always - if you have any questions feel free to ask. All you need to do now is to style it

Comments on this post
RickJ agrees: Superb teacher!!
Attached Files
File Type: txt testpage.txt (1.9 KB, 365 views)
  Reply With Quote
 
     
 
 
Old May 11, 2006, 06:00 AM   #9  
Über Member
RickJ is offline
 
RickJ's Avatar
 
Join Date: Aug 2005
Location: The Bogs at Windover
Posts: 7,363
RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.RickJ See this member's comment history on his/her Profile page.
Awesome, Lee! I was able to follow along to get it right:
LTheobald is too cool!

I grant that I do not yet fully understand it, but you've given me an excellent tutortial to learn from.

Thank you so much, LT!
  Reply With Quote
 
     
 
 
Old May 11, 2006, 06:46 AM   #10  
Ultra Member
LTheobald is offline
 
LTheobald's Avatar
 
Join Date: Feb 2004
Location: Cambridge, UK
Posts: 1,047
LTheobald See this member's comment history on his/her Profile page.LTheobald See this member's comment history on his/her Profile page.
Call LTheobald via Skype™ Send a message via MSN to LTheobald
Well if there's a certain bit you are unsure about Rick - ask.

Also if you want some extra changes (e.g. click to expand/shrink - at the moment clicking just expands), let me know what you want and I'll see what I can do.
  Reply With Quote
 
     

Your Answer
Email me when someone replies to my answer
Join Login



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Ask your question or search...



Similar Threads
Expanding an existing concrete patio
(1 replies)
Expanding washer
(3 replies)
Collapsing answers in list of questions.
(16 replies)
List box
(0 replies)
Website Tree List not expanding
(1 replies)

Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page
Search this Thread

Advanced Search

Bookmarks





Copyright ©2003 - 2009, Ask Me Help Desk.
All times are GMT -8. The time now is 11:05 AM.