How to add a basic dropdown menu to your blogger powered blog

In this tutorial i will show you how to add a basic dropdown navigation menu to your blogger powered blog so i recommend you create a test blog or download a backup copy of your template before doing anything as i cannot be held responsible if you mess your blog layout up.

for this tutorial i'm going to use the minima template however it should work with most blogger templates once you have your template go to layout > Edit html and paste the following code just before the <div id='content-wrapper'>


<div id='nav'>
<ul>
<li class='firstchild'><a href='/'>Home</a></li>
<li><a href='#'>About</a>
<ul>
<li><a href='#'>Link 1</a></li>
<li><a href='#'>Link 2</a></li>
<li><a href='#'>Link 3</a>
<ul>
<li><a href='#'>Link 3a</a></li>
<li><a href='#'>Link 3b</a></li>
</ul>
</li>
<li><a href='#'>Link 4</a>
<ul>
<li><a href='#'>Link 4a</a></li>
<li><a href='#'>Link 4b</a></li>
<li><a href='#'>Link 4c</a></li>
<li><a href='#'>Link 4d</a></li>
</ul>
</li>
<li><a href='#'>Link 5</a></li>
</ul>
</li>

<li><a href='#'>Links</a>
<ul>
<li><a href='#'>Link 1</a></li>
<li><a href='#'>Link 2</a></li>
<li><a href='#'>Link 3</a></li>
<li><a href='#'>Link 4</a>
<ul>
<li><a href='#'>Link 4a</a></li>
<li><a href='#'>Link 4b</a></li>
</ul>
</li>
</ul>
</li>

<li><a href='http://www.blogger.com'>Blogger</a>
<ul>
<li><a href='http://help.blogger.com/'>Help Centre</a></li>
<li><a href='http://status.blogger.com/'>Blogger Status</a></li>
</ul>
</li>
</ul>
</div>


if you are not sure where to paste it see this screenshot note you will need to change every # to the actual link for the links to work like i have in the last link list now we are going to add some CSS code for the structure and style of the dropdown menu if you happen to know CSS you can tweak it further to your liking

#nav {
padding:0;
margin:0;
font-family: arial,helvetica,serif;
font-size: 16px;
clear:both;
}
#nav ul {
padding:0;
margin:0;
list-style:none;
line-height:1;
}
#nav a {
display:block;
width:10em;
margin:0;
padding:3px 5px;
color:#58a;
}
#nav a:hover{
text-decoration:none;
color:#fff;
background:#58a;
}
#nav ul li {
float:left;
width:10em;
border-bottom:1px solid #dcdcdc;
border-right:1px solid #dcdcdc;
border-top:1px solid #dcdcdc;
background:#fff;
overflow:hidden;
}
#nav ul li ul li {
border-top:0;
border-left:1px solid #dcdcdc;
}
#nav ul li ul li ul li {
border-top:0;
}
#nav ul li.firstchild{
border-left:1px solid #dcdcdc;
}
#nav ul li ul {
position: absolute;
margin:1px 0 0 -1px;
width:10em;
left:-999em;
}
#nav ul li ul ul {
margin:-23px 0 0 160px;
border-top:1px solid #dcdcdc;
}
#nav ul li:hover ul ul,
#nav ul li.sfhover ul ul {
left:-999em;
}
#nav ul li:hover ul,
#nav ul li li:hover ul,
#nav ul li.sfhover ul,
#nav ul li li.sfhover ul {
left:auto;
}


since IE 6 and 7 do not support the :hover pseudo-selector for non-links this will not work unless we add a small javascript thanks to htmldog for the script so go ahead and add the following script just before the closing </head> tag



<script type='text/javascript'>
//<![CDATA[
sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover"; }
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//]]>
</script>


now you should have a basic dropdown menu see my result thanks for reading your comments are welcome.

16 Responses to “How to add a basic dropdown menu to your blogger powered blog”

For some reason the drop downs when I hover over the link are hidden behind my sidebars and my main wrapper. Can you help me?

@Anonymous
what is the url of the site ?

My article is about same theme but with use of more powerful jQuery drop down multi level menu Superfish. Click on link to find out more.

And you have div size problem when users publish comment on you blog on Firefox.

@Mark
what div size problem are you seeing ? because i'm using firefox and i can't see any problem

You have an awesome blog! I have linked your blog to my blog http://blogger-templates123.blogspot.com

awesome! thanks. best script ever

thanks, whats the code to stop the bar from moving. i have split my header into 2 colums, so the drop down menu is up in the header. i want it above posts. any help?

@Rabih
the navigation is already above your posts

How do you change the background color?

how to increase the width??? as u can see on my blog, the last part is broken (i want it to go till the end).

@Anonymous
look for the following CSS code

#nav ul li {
float:left;
width:10em;
border-bottom:1px solid #dcdcdc;
border-right:1px solid #dcdcdc;
border-top:1px solid #dcdcdc;
background:#fff;
overflow:hidden;
}

change the hex colour code on the background property for example

#nav ul li {
float:left;
width:10em;
border-bottom:1px solid #dcdcdc;
border-right:1px solid #dcdcdc;
border-top:1px solid #dcdcdc;
background:#f00;
overflow:hidden;
}

in the example CSS above i used #f00 which is a red colour have a look at this link for colour hex codes

@rabih
that is left to the reader to modify the CSS code to suit their site

http://megatrend-analysis.blogspot.com/search/label/News

the text goes behind the widget! any ideas how to fix it. i really love ur script, but for some reason it keeps going wrong with me. i will be launching my website by the beginning of the year, and i want it to be ready. i will add your website on my fav links. plz help!

Thanks Lawny!
I know this sounds silly but, do you know how to change the text color?

@Rabih
sorry i don't have time


@Anonymous
look for the following CSS code

#nav a {
display:block;
width:10em;
margin:0;
padding:3px 5px;
color:#58a;
}

change the color property example

#nav a {
display:block;
width:10em;
margin:0;
padding:3px 5px;
color:#f00;
}

in the example above i change the text to a red colour

Rabih,
To increase the width, look for this line:

}
#nav ul li {
float:left;
width:10em;
border-bottom:1px solid #dcdcdc;
border-right:1px solid #dcdcdc;
border-top:1px solid #dcdcdc;
background:#2e1a11;
overflow:hidden;
}

Change the 10 before the EM part to whatever number you want. (The lower the number, the shorter the width)

Leave a Reply

Feel free to leave your comment however comments are moderated before appearing on site

Copyright © 2009 All Rights Reserved | Privacy Policy | Disclaimer Design by LawnyDesigns | Powered by Blogger