Menu
Posted: Thu Mar 08, 2012 4:11 pm
Hi guys,
I am trying to learn Jquery, I usually try to build every thing by myself as I think it is the best way to learn, but I am in a rush for this
I am trying to build a drop down menu, here is the code:
HTML
CSS
JAVASCRIPT
OK this is working fine but what I want to to do is add a submenu into the submenu, like UL slide out when user hover over submenu feature 2.
Other thing I am not understanding is what is the use of <div class="clear"></div> in the above code.
I am trying to learn Jquery, I usually try to build every thing by myself as I think it is the best way to learn, but I am in a rush for this
I am trying to build a drop down menu, here is the code:
HTML
Code: Select all
<ul id="nav">
<li><a href="#" class="selected">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Pages +</a>
<ul>
<li style="border-top:0px;"><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
<div class="clear"></div>
</li>
<li><a href="#">Features +</a>
<ul>
<li style="border-top:0px;"><a href="#">Feature 1</a></li>
<li><a href="#">Feature 2</a></li>
<li><a href="#">Feature 3</a></li>
<li><a href="#">Feature 4</a></li>
</ul>
<div class="clear"></div>
</li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
<div class="clear"></div>
Code: Select all
body {font-family:arial; font-size:12px; background:#F1F1F1;}
.clear {clear:both}
/* remove the list style */
#nav {
margin:0;
padding:0;
list-style:none;
}
/* make the LI display inline */
/* it's position relative so that position absolute */
/* can be used in submenu */
#nav li {
float:left;
display:block;
position:relative;
z-index:500;
margin:0 1px;
}
/* this is the parent menu */
#nav li a {
display:block;
padding:10px;
font-weight:700;
height:23px;
text-decoration:none;
color:#333333;
text-align:center;
color:#333;
}
#nav li a:hover {
color:#FF9921;
}
/* you can make a different style for default selected value */
#nav a.selected {
color:#FF9921;
}
/* submenu, it's hidden by default */
#nav ul {
position:absolute;
left:0;
display:none;
margin:0 0 0 -1px;
padding:0;
list-style:none;
}
#nav ul li {
float:left;
border-top:1px solid #fff;
background:#d7d7d7;
}
/* display block will make the link fill the whole area of LI */
#nav ul a {
display:block;
height:15px;
padding:10px;
color:#666;
}
#nav ul a:hover {
text-decoration:underline;
}
/* fix ie6 small issue */
/* we should always avoid using hack like this */
/* should put it into separate file : ) */
*html #nav ul {
margin:0 0 0 -2px;
}
Code: Select all
<script type="text/javascript">
$(document).ready(function () {
$('#nav li').hover(
function () {
//show its submenu
$('ul', this).slideDown(100);
},
function () {
//hide its submenu
$('ul', this).slideUp(100);
}
);
});
</script>
Other thing I am not understanding is what is the use of <div class="clear"></div> in the above code.