Learning Exercise - Horiz. Nav. Multi-Col. Submenu

nbourg8

New Member
Hey all, found this website when searching for an answer to an earlier question I had when I discovered I had a bigger problem at hand.

As the title suggests, I'm doing a learning exercise with horizontal navigation menu bars which contain multiple column sub-menus. This is in response to a high amount of information being accessed from the main page rather than a series of sub-pages. My problem comes when trying to make the sub-menu work for more than 1 button of the nav bar.

Summary of setup:
I created a smaller div to house each column inside a container div for each sub-menu. Thus, 1 sub-menu has up to 5 smaller div's in it to create the column effect. My problem was realized when I tried to display this div from each list, finding it off center or misaligned.

I'm unsure if this is even the correct path towards accomplishing this task but I'm open to all suggestions and corrections. I appreciate your time and help.

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Travis' Homepage</title>
    <link rel="stylesheet" href="styles/stylesheet.css" type="text/css" />
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="topnav">
                <ul>
                    <li><a href="#">Home</a></li>
                    <li><a href="#">Social Networking</a></li>
                    <li><a href="#">News</a></li>
                    <li><a href="#">Forums</a>
						<div class="subnav-container">
							<div class="subnav">
								<h3>Anything Based forums</h3>
								<ul>
									<li>
										<a href="#">General [M]ayhem Forums</a>
									</li>
								</ul>
							</div>
							<div class="subnav">
								<h3>Car Based</h3>
								<ul>
									<li><a href="#">502 Street Scene</a></li>
									<li><a href="#">Louisville Streets</a></li>
									<li><a href="#">Cincinatti Street Scene</a></li>
									<li><a href="#">VW Vortex</a></li>
									<li><a href="#">3000GT/Stealth International</a></li>
									<li><a href="#">Fourtitude</a></li>
									<li><a href="#">502 Underground</a></li>
									<li><a href="#">DSM Talk Forums</a></li>
									<li><a href="#">DSM Tuners Forums</a></li>
									<li><a href="#">DSM Link forums</a></li>
								</ul>
							</div>
							<div class="subnav">
								<h3>Computer</h3>
								<ul>
									<li><a href="#">2 CPU Forums</a></li>
									<li><a href="#">ALR Revolution 6x6 Website/Forum</a></li>
									<li><a href="#">[H]ard | Forum</a></li>
									<li><a href="#">Real Red Raider Forum</a></li>
									<li><a href="#">Xtreme Systems Forums</a></li>
									<li><a href="#">Maximum PC Forums</a></li>
									<li><a href="#">Overclock.net Forums</a></li>
								</ul>
							</div>
							<div class="subnav">
								<h3>Video Game</h3>
								<ul>
									<li><a href="#">Gran Turismo Planet(GTP)</a></li>
									<li><a href="#">Gameshark/Sharkport</a></li>
									<li><a href="#">Forza Central</a></li>
									<li><a href="#">[H]ard | Gaming</a></li>
									<li><a href="#">Clan Riot Squad [RS]</a></li>
									<li><a href="#">Netcode Illuminati</a></li>
									<li><a href="#">TC Admin</a></li>
									<li><a href="#">GSP Talk</a></li>
								</ul>
							</div>
							<div class="subnav">
								<h3>R/C Car Based</h3>
								<ul>
									<li><a href="#">The Starting Grid</a></li>
									<li><a href="#">Xtreme R/C Cars</a></li>
									<li><a href="#">Traxxas</a></li>
									<li><a href="#">RC Universe</a></li>
									<li><a href="#">R/C Tech</a></li>
									<li><a href="#">Ofna Back Talk</a></li>
									<li><a href="#">Beat Your Truck</a></li>
									<li><a href="#">Unlimited Engineering</a></li>
								</ul>
							</div>
						</div>
					</li>
                    <li><a href="#">Hosting</a></li>
                    <li><a href="#">P. Sites</a></li>
                </ul>
            </div>
        </div>
		<div class="footer">
			Created by <a href="#">ME!</a>
		</div>
	</div>
</body>
</html>

and the stylesheet
HTML:
html, body {
    margin:0;
    padding:0;
    background:#555555;
    font:12px Verdana, Sans-serif;
}
.container{
    width:960px;
    margin:20px auto 0;
	text-align:center;
}
.header .topnav{
	display:inline-block;
	margin:10px 0 0 0;
	font: bold 12px Verdana, Sans-serif;
}
.header .topnav ul{
	clear:left;
	float:left;
	list-style:none;
	margin:0;
	padding:0;
	display:block;
	text-align:center;
	position:relative;
}
.header .topnav ul li {
	display:block;
	float:left;
	position:relative;
}
.header .topnav ul li a {
	display:block;
	float: left;
	padding: 10px 20px;
	text-decoration:none;
	color:#777;
	box-shadow: 0 0 3px black;
	background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#d9d9d9));
}
.header .topnav ul li a:hover,
.header .topnav ul li:hover > a {
	color: #ac0000;
}
.subnav-container{
	position:absolute;
	top:100%;
	left:-999em;
	z-index:99;
	width:960px;
	background:#919191;
}
.subnav-container .subnav{
	float:left;
	width:192px;
}
.subnav-container .subnav h3{
	font-size:10px;
}
.subnav-container .subnav ul{
}
.subnav-container .subnav ul li a{
	width:150px;
	background:none;
	color:black;
	border:none;
	box-shadow:none;
}
.header .topnav ul li:hover .subnav-container{
	clear:both;
	left:-505px;
}

THANKS!
 

PixelPusher

Super Moderator
Staff member
Holy sub menu batman!!

Ok if your are gonna use html5, might as well use some of the semantic tags and also remove some of the redundant classes. I added/adjusted for you. This is a rough crack at this. The css could be written a little cleaner, but at least this get you going in the right direction :D. PM if you need more help, or others here will definitely have input. So without further adieu...

HTML
HTML:
<body>
    <div class="wrapper">
        <header>
            <nav>
                <ul>
                    <li><a href="#">Home</a></li>
                    <li><a href="#">Social Networking</a></li>
                    <li><a href="#">News</a></li>
                    <li><a href="#">Forums</a>
						<div class="container">
							<div>
								<h3>Anything Based forums</h3>
								<a href="#">General [M]ayhem Forums</a>
							</div>
							<div>
								<h3>Car Based</h3>
								<ul>
									<li><a href="#">502 Street Scene</a></li>
									<li><a href="#">Louisville Streets</a></li>
									<li><a href="#">Cincinatti Street Scene</a></li>
									<li><a href="#">VW Vortex</a></li>
									<li><a href="#">3000GT/Stealth International</a></li>
									<li><a href="#">Fourtitude</a></li>
									<li><a href="#">502 Underground</a></li>
									<li><a href="#">DSM Talk Forums</a></li>
									<li><a href="#">DSM Tuners Forums</a></li>
									<li><a href="#">DSM Link forums</a></li>
								</ul>
							</div>
							<div>
								<h3>Computer</h3>
								<ul>
									<li><a href="#">2 CPU Forums</a></li>
									<li><a href="#">ALR Revolution 6x6 Website/Forum</a></li>
									<li><a href="#">[H]ard | Forum</a></li>
									<li><a href="#">Real Red Raider Forum</a></li>
									<li><a href="#">Xtreme Systems Forums</a></li>
									<li><a href="#">Maximum PC Forums</a></li>
									<li><a href="#">Overclock.net Forums</a></li>
								</ul>
							</div>
							<div>
								<h3>Video Game</h3>
								<ul>
									<li><a href="#">Gran Turismo Planet(GTP)</a></li>
									<li><a href="#">Gameshark/Sharkport</a></li>
									<li><a href="#">Forza Central</a></li>
									<li><a href="#">[H]ard | Gaming</a></li>
									<li><a href="#">Clan Riot Squad [RS]</a></li>
									<li><a href="#">Netcode Illuminati</a></li>
									<li><a href="#">TC Admin</a></li>
									<li><a href="#">GSP Talk</a></li>
								</ul>
							</div>
							<div>
								<h3>R/C Car Based</h3>
								<ul>
									<li><a href="#">The Starting Grid</a></li>
									<li><a href="#">Xtreme R/C Cars</a></li>
									<li><a href="#">Traxxas</a></li>
									<li><a href="#">RC Universe</a></li>
									<li><a href="#">R/C Tech</a></li>
									<li><a href="#">Ofna Back Talk</a></li>
									<li><a href="#">Beat Your Truck</a></li>
									<li><a href="#">Unlimited Engineering</a></li>
								</ul>
							</div>
						</div>
					</li>
                    <li><a href="#">Hosting</a></li>
                    <li><a href="#">P. Sites</a></li>
                </ul>
            </nav>
        </header>
		<footer>
			Created by <a href="#">ME!</a>
		</footer>
	</div>
</body>

CSS
Code:
nav ul {
		list-style:none;
	}
	nav > ul > li {
		float:left;
		height:40px;
		position:relative;
		overflow:hidden;
		margin-right:10px;
	}
	nav ul li a {
		display:inline-block;
		font:1em/1.4em Georgia, "Times New Roman", Times, serif;
		color:#333;
		text-decoration:none;
		padding:0 15px;
		white-space:nowrap;
	}
	nav ul li a:hover {
		color:green;
		background-color:#e1e1e1;
	}		
	ul div.container {
		display:none;
		position:absolute;
		top:10px;
		left:0;
	}
	ul li:hover div.container {
		display:block;
	}
	ul li:hover {
		height:auto;
		overflow:visible;
	}
	ul h3 {
		font:normal 1.2em/1.5em "Trebuchet MS", Arial, Helvetica, sans-serif;
		color:#666;
		margin-bottom:10px;
		border-bottom:dotted 1px #ddd;
	}
	ul div.container a {
		font:0.9em/1.1em "Trebuchet MS", Arial, Helvetica, sans-serif;
		color:#777;
	}
	ul div.container a:hover {
		color:red;
		background:none;
	}
	footer {
		clear:both;
		margin-top:50px;
	}

(Tested in Firefox 6)
 

nbourg8

New Member
Wow. See, this is the structure I need. I knew there should be an overall standard way to do this which would be both efficient and elegant but no tutorial out there can teach what you've just shown me.

This revelation aside, my original problem wasn't answered unfortunately. My question to you may now be more clear since you clearly dove into my project.

Question: If you now took that submenu, and wanted to slam it up against the left side of the website, not just the nav bar itself and not against the left side of the browser. Assume browser size and site resolution are irrelevant.

My observation: Using the method described, if you simply applied the style property "Left" you could adjust the div for only menu selection. And knowing that the "Left" property would apply to all the menu selections available, can this be done without use of javascript?

Example: If all the submenu's could be displayed in one, the same, location on the left side, I think this could lead to the answer of my problem.
 

PixelPusher

Super Moderator
Staff member
OK so you want the sub menu to always appear on the left edge of the browser window no matter what? That seems a little odd, if the main menu is positioned elsewhere. Or is the whole menu going to be on the left edge as well?
 

PixelPusher

Super Moderator
Staff member
The ultimate goal would be to have the style of columnized menu system found in the link below.

http://www.statoil.com/

Wow that is a huge sub menu, damn near covers the whole site...and just so you know they are using js to make that function. It is adding removing an inline style for the "megaMenu".

Might be possible with css. I will take a look.
 

PixelPusher

Super Moderator
Staff member
OK check this out, you will want to adjust styling but the concept is similar to what your looking for...i think :p No js here.

HTML
HTML:
<body>
    <div id="wrapper">
        <header>
            <nav>
                <ul>
                    <li><a href="#">Home</a></li>
                    <li><a href="#">Social Networking</a></li>
                    <li><a href="#">News</a></li>
                    <li><a href="#">Forums</a>
			<div class="grid">
                           <div>
                                <section>
                                    <h3>Anything Based forums</h3>
                                    <a href="#">General [M]ayhem Forums</a>
                                </section>
                                <section>
                                    <h3>Car Based</h3>
                                    <ul>
                                        <li><a href="#">502 Street Scene</a></li>
                                        <li><a href="#">Louisville Streets</a></li>
                                        <li><a href="#">Cincinatti Street Scene</a></li>
                                        <li><a href="#">VW Vortex</a></li>
                                        <li><a href="#">3000GT/Stealth International</a></li>
                                        <li><a href="#">Fourtitude</a></li>
                                        <li><a href="#">502 Underground</a></li>
                                        <li><a href="#">DSM Talk Forums</a></li>
                                        <li><a href="#">DSM Tuners Forums</a></li>
                                        <li><a href="#">DSM Link forums</a></li>
                                    </ul>
                                </section>
			   </div>
			   <div>
				<section>
                                    <h3>Computer</h3>
                                    <ul>
                                        <li><a href="#">2 CPU Forums</a></li>
                                        <li><a href="#">ALR Revolution 6x6 Website/Forum</a></li>
                                        <li><a href="#">[H]ard | Forum</a></li>
                                        <li><a href="#">Real Red Raider Forum</a></li>
                                        <li><a href="#">Xtreme Systems Forums</a></li>
                                        <li><a href="#">Maximum PC Forums</a></li>
                                        <li><a href="#">Overclock.net Forums</a></li>
                                    </ul>
                                </section>
				<section>
                                    <h3>Video Game</h3>
                                    <ul>
                                        <li><a href="#">Gran Turismo Planet(GTP)</a></li>
                                        <li><a href="#">Gameshark/Sharkport</a></li>
                                        <li><a href="#">Forza Central</a></li>
                                        <li><a href="#">[H]ard | Gaming</a></li>
                                        <li><a href="#">Clan Riot Squad [RS]</a></li>
                                        <li><a href="#">Netcode Illuminati</a></li>
                                        <li><a href="#">TC Admin</a></li>
                                        <li><a href="#">GSP Talk</a></li>
                                    </ul>
                                </section>
			   </div>
			   <div>
                            	<section>
                                    <h3>R/C Car Based</h3>
                                    <ul>
                                        <li><a href="#">The Starting Grid</a></li>
                                        <li><a href="#">Xtreme R/C Cars</a></li>
                                        <li><a href="#">Traxxas</a></li>
                                        <li><a href="#">RC Universe</a></li>
                                        <li><a href="#">R/C Tech</a></li>
                                        <li><a href="#">Ofna Back Talk</a></li>
                                        <li><a href="#">Beat Your Truck</a></li>
                                        <li><a href="#">Unlimited Engineering</a></li>
                                    </ul>
                                </section>
			   </div>
			   </div>
		    </li>
                    <li><a href="#">Hosting</a></li>
                    <li><a href="#">P. Sites</a></li>
                </ul>
            </nav>
        </header>
        <section id="main">
           <!-- your site content -->
        </section
        <footer>
		Created by <a href="#">ME!</a>
	</footer>
   </div>
</body>
CSS
Code:
header, nav, footer {
		display:block;
	}
	#wrapper {
		margin:0 auto;
		width:960px;
		height:600px; /* not needed when site has content, just for example purposes */
		border-left:solid 1px red;
		border-right:solid 1px red;
	}
	nav ul {
		position:relative;
		list-style:none;
	}
	nav > ul > li {
		float:left;
		height:40px;
		
		overflow:hidden;
		margin-right:10px;
	}
	nav ul li a {
		display:inline-block;
		font:1em/1.4em Georgia, "Times New Roman", Times, serif;
		color:#333;
		text-decoration:none;
		padding:0 15px;
		white-space:nowrap;
	}
	nav ul li a:hover {
		color:green;
		background-color:#e1e1e1;
	}		
	ul div.grid {
		background-color:#777;
		display:none;
		overflow:hidden;
		position:absolute;
		top:30px;
		left:0;
		width:100%;
	}
	ul div.grid > div {
		float:left;
		margin:5px 30px 0 0;
		width:290px;
	}
	ul div.grid section {
		margin-bottom:20px;
	}
	ul li:hover div.grid {
		display:block;
	}
	ul h3 {
		font:normal 1.2em/1.5em "Trebuchet MS", Arial, Helvetica, sans-serif;
		color:#444;
		margin-bottom:10px;
		padding:0 10px;
		text-shadow:0 1px 1px #999;
	}
	ul div.grid a {
		font:0.9em/1.1em "Trebuchet MS", Arial, Helvetica, sans-serif;
		color:#fff;
	}
	ul div.grid a:hover {
		color:red;
		background:none;
	}
	nav ul ul {
		margin:0;
		padding:0;
	}
	footer {
		clear:both;
		margin-top:50px;
		display:none;
	}

*NOTE: tested in latest versions of FireFox, Chrome, and Safari.
 

PixelPusher

Super Moderator
Staff member
What i did just to help you understand, is remove the relative position from the parent (sub menu containing) list item and added it to the list instead. Why?

An absolute positioned element will position itself to the first parent that has a position property of anything other than "static" (default). If none exists, then this parent will be the html element.

I also added a grid to the sub menu so you can stack the link groups next to each other in columns. Very basic grid, but it gives you the idea.

As always, if you have questions feel free to ask.
 
Top