Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

CSS Dropdown menu

Please look at the following code and CSS.  I'm creating a popout and dropdown menu.

The second part, the dropdown part I can not seem to get working correct.  Can you please have a look and give me some advise about what to fix?

Thanks in advance.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Menu</title>
<style>
	nav, nav ul, nav li{
	padding:0;
	margin:0;
	}
	

	
nav ul li {
	font-family:Arial, Helvetica, sans-serif;
	font-size:.95em;
	color:#908f8f;
	float: left;
	background-image:url(../img/nav/nav-arrow.png);
	background-repeat:no-repeat;
	background-position:left;
	padding-left:5%;
	list-style: none;
	position: relative;
	width:110px;
	height: 30px;
	clear:left;
	background-color:#000;
	line-height: 30px;
	cursor:pointer;
}

	nav li a{
	text-decoration:none;
	color: white;
	float:left;
	}
	nav li:hover{
	background-color:none;
	}
	
	nav ul ul{
	position:relative;
	top:-30px;
	width:120px;
	left:110px;
	padding-left:5%;
	visibility:hidden;
	background-color:#333333;
	}
	nav ul li:hover ul{
	visibility:visible;
	}
	
	nav ul ul li:hover	{
		background-color:none;
	}
	
	nav ul ul li:hover ul{
	visibility:visible;
	}
	
	nav ul ul ul	{
		visibility:hidden;
	}

	
nav ul {
	background:;  
	padding-left:;
	margin:;
	list-style: ;
	position:;
}
	nav ul:after {
		content:;
		clear:; 
		display:;
	}

nav ul li {
	background-image:;
	font-family:;
	color:;
	float:;
	background-image:;
	background-repeat:;
	background-position:;
	padding-left:;
}
	nav ul li:hover {

	}
		nav ul li:hover a {
			color:;
		}
	
	nav ul li a {
		font-family:;
		display:; 
		color:;
		text-decoration:;
		padding:;
	}
	
	nav ul ul li  {
		float:; 
		color:;
		position:;
		font-family:Arial, Helvetica, sans-serif;
		font-size:;
		left:;
		padding:0% 0% 0% 10%;
		width:110px;
	}
		nav ul ul li:hover  {
		float:left;
		color:; 
		position: ;
		background:;
	}

	nav ul ul li a {
			padding:0% 0% 0% 0%;
		}	
			nav ul ul li a:hover {
				background: #none;
				color:#d9702a; 
			}

nav ul ul ul {
	position:absolute; 
	left:0px; 
	top:15px;
	width:100px;
	height:75px;
	background-color:#000000;
	visibility:hidden;
}
nav ul ul ul li  {
		float:; 
		color:;
		position:;
		font-family:Arial, Helvetica, sans-serif;
		font-size:;
		left:;
		padding:0% 0% 0% 10%;
		width:110px;	
}
nav ul ul ul ul {
	position:; 
	left:; 
	top:;
	width:100px;
	background-color:;
}


nav ul ul ul ul li a:hover {
	color:;
}
</style>
</head>

<body>

<div id="top_menu">
	<nav>
		<ul>
			<li><a href="#">PRODUCTS</a>
				<ul>
					<li>AMPLIFIERS
						<ul>
							<li><a href="#">MicroPro 200</a>
								<ul>
									<li><a href="#">Micro Proo 200 8"</a></li>
									<li><a href="#">Micro Pro 200 10"</a></li>
									<li><a href="#">Micro Pro 200 12"</a></li>
									<li><a href="#">Micro Pro 200 Head</a></li>
								</ul>
							</li>
							<li><a href="#">Aviator</a></li>
						</ul>
					</li>
					<li><a href="#">CABINETS</a></li>
					<li><a href="#">ACCESSORIES</a></li>
				</ul>
			</li>
			<li><a href="#">EXPERIENCE</a></li>
			<li><a href="#">PATRICK</a></li>
			<li><a href="#">CONTACT</a></li>
		</ul>
	</nav>
</div>
</body>
</html>

Open in new window

0
rgranlund
Asked:
rgranlund
  • 2
1 Solution
 
Kyle HamiltonData ScientistCommented:
your css is much too complicated.

This is using CSS from another example, so you'll have to adjust colors to your liking:

http://candpgeneration.com/EE/another-dd.html

(view source)
0
 
RartemassAuthor, martial arts coach, IT ConsultantCommented:
To expand on kozaiwaniec's response, here are some reasons why it is too complicated.

-You list nav ul li {} twice in the CSS. By design, whatever comes last in the style sheet is the one the applies. So if you have the same thing listed twice, only the bottom most style will apply.

-You have things like nav ul ul ul ul ul li {}. This is quite difficult to remember where on the page you actually are. If you need that level of complexity you really need to name your elements with an ID or a class. An ID is unique and should only be used once in the code. A class can be repeated multiple times in the code. So if you want the same style applying to multiple elements, use a class and assign that class a style via CSS.
To apply a class to an element you would use class="name" like you did for the ID in your code.
This link explains the two:
http://www.w3schools.com/css/css_id_class.asp

My preference is to have each menu level as a new class. For example:
<ul id="topMenu">
<li><a href="link1.html">Vegies</a></li>
<li><a href="link2.html">Meat</a></li>
<li><a href="link3.html">Fruit</a>
   <ul class="secondLevel">
        <li><a href="link4.html" class="subItem">Citrus</a>
                <ul class="thirdLevel">
                       <li><a href="link5.html">Oranges</a></li>
                       <li><a href="link6.html">Key Lime</a></li>
                </ul>
       </li>
   </ul>
 </li>
</ul>

Open in new window


With all the specific names here, I can drill down exactly where I want to style them in the CSS.
For example:
#topMenu li { float: left;}
#topMenu ul.secondLevel {color: #FFFFFF;}
.subItem {background: url(image/arrow.gif) center right no-repeat;}
.thirdLevel li {padding-right: 0.2em;}

Open in new window


To give you more examples, I like the Son of Suckerfish menu layout presented here:
http://www.htmldog.com/articles/suckerfish/dropdowns/

The multi-level menu is about half way down the page. Working examples have links at the bottom.
0
 
Kyle HamiltonData ScientistCommented:
suckerfish menus are also too complex, and moreover require javascript. yuk.

this is all the css you need for the above example (including the animation effect which gets ignored in old versions of IE):


      
nav a{
                text-decoration: none;
                text-transform: uppercase;
                color:#333;
                font-family: geneva, sans-serif;
                font-size:14px;
                background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAUCAYAAABWMrcvAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAg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YII=') right center no-repeat;

            }
            nav ul{
                margin:0;
                padding:0;
            }
            .menu li{
                position:relative;
                width:220px;
                display:block;
                background-color:#eee;
                border-top:1px solid white;
                border-bottom:1px solid white;
                padding:0;
                margin:0;
                list-style: none;
                
                -webkit-transition: all 0.3s ease;
                -moz-transition: all 0.3s ease;
                -o-transition: all 0.3s ease;
                -ms-transition: all 0.3s ease;
                transition: all 0.3s ease;
            }
            .menu ul{
                display:none;
                width:0;
                position:absolute;
                left:220px;
                top:-1px; /* accommodate the border */
               
            }
            
            .menu li a{
                display:block;
                padding:7px 7px 2px;
                margin:3px;
                -webkit-transition: all 0.5s ease;
                -moz-transition: all 0.5s ease;
                -o-transition: all 0.5s ease;
                -ms-transition: all 0.5s ease;
                transition: all 0.5s ease;
            }
            .menu li:hover{
                background-color: #ccc;
            }
            .menu li:hover > a{
                background-color: yellowgreen;
                color:darkslategray;
            }
            
            .menu li:hover > ul{
                display:block;
            }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now