< Buzzing or vibrating the login form using jquery Posted On May 15, 2012 : 0 comments << >> Simple div slideshow using jquery Posted On May 9, 2012 : 0 comments << >> Copy mysql column in varchar to type date Posted On May 3, 2012 : 0 comments << >> Enter only numbers inside a input field of a form using javascript Posted On May 1, 2012 : 0 comments << >> Slide in and out animate div vertically using jquery Posted On April 25, 2012 : 1 comment << >> Tag cloud using php, mysql and ajax with filter Posted On April 24, 2012 : 0 comments << >> Change webpage font color or background color from the user side using javascript Posted On April 19, 2012 : 0 comments << >> A single link that cycles through several webpage background color using javascript Posted On April 17, 2012 : 0 comments << >> Simple webpage redirection using perl script Posted On April 10, 2012 : 0 comments << >> Get ipaddress using perl script Posted On April 4, 2012 : 0 comments << >>

Simple CSS Dropdown Menu

This Tutorial Has Been Viewed 2,143 Times.
VN:F [1.9.17_1161]
Rating: 10.0/10 (2 votes cast)

Here is a simple CSS dropdown menu which you can simply copy and paste for your website.

AS I ALWAYS SAY TAKE CARE OF THE QUOTES WHILE COPYING, USE DREAMWEAVER TO EDIT THE CODE

The CSS Code

This is the part that gives the dropdown structure. Without the CSS, all you’ll get is plain HTML only output.

Filename: dropdown.css

 

ul.dropdown {
 margin0;
 padding0;
 list-stylenone;
 floatleft;
 width100%;
}
.dropdown li {
 margin0;
 padding0;
 floatleft;
 positionrelative;
}
.dropdown ul {
 displaynone;
 floatnone;
 margin0;
 padding0;
 list-stylenone;
}
.dropdown li li {
 floatnone;
 displayinline;
 white-spacenowrap;
}

.dropdown li:hover ul, .dropdown li.lihover ul {
 positionabsolute;
 displayblock;
}

.dropdown a {
 displayblock;
 padding3px 10px;
 margin0 1px 1px 0;
 font-family: Arial, Helvetica, sans-serif;
 font-size9pt;
 background#080;
 color#fff;
 text-decorationnone;
}

.dropdown a:hover {
 background#0a0;
}

The Internet Explorer Javascript Hack

Hey! Didn’t I say CSS? Why do I need Javascript? Well, if the guys in Microsoft just followed CSS standards properly then we won’t need to put this javascript. Yes, this is here because we don’t want to make those IE users feel left out.

Filename: dropdown.js

 

var liHover = function () {
 var liEls = document.getElementById (“dropdown”).getElementsByTagName (“LI”);
 for (var i = 0; i < liEls.length; i++) {
  liEls[i].onmouseover = function () {
   this.className += ” lihover”;
  }
  liEls[i].onmouseout = function () {
   this.className = this.className.replace (new RegExp (” lihover\\b”)“”);
  }
 }
}
if (window.attachEvent) window.attachEvent (“onload”, liHover);

The HTML

Finally, here’s the stuff that puts these things together, the html page.

Filename: MainPage.html

<html xmlns=“http://www.w3.org/1999/xhtml”>
 <head>
  <title>CSS Dropdown</title>
  <link rel=“stylesheet” type=“text/css” href=“dropdown.css” />
  <script language=“javascript” src=“dropdown.js”></script>
 </head>
 <body>
  <ul class=“dropdown” id=“dropdown”>
   <li><a href=“#”>Main Link 1</a>
    <ul>
     <li><a href=“#”>Sublink 1-1</a></li>
     <li><a href=“#”>Sublink 1-2</a></li>
     <li><a href=“#”>Sublink 1-3</a></li>
     <li><a href=“#”>Sublink 1-4</a></li>
    </ul>
   </li>
   <li><a href=“#”>Main Link 2</a>
    <ul>
     <li><a href=“#”>Sublink 2-1</a></li>
     <li><a href=“#”>Sublink 2-2 lipsum</a></li>
     <li><a href=“#”>Sublink 2-3</a></li>
     <li><a href=“#”>Sublink 2-4</a></li>
    </ul>
   </li>
   <li><a href=“#”>Main Link 3</a></li>
  </ul>
 </body>
</html>

There you go. Copy and paste the code into their proper filenames and check it out.

VN:F [1.9.17_1161]
Rating: 10.0/10 (2 votes cast)

Simple CSS Dropdown Menu, 10.0 out of 10 based on 2 ratings

Incoming search terms:





You will also be interested in ,

Tags: ,

Leave a Reply

Proudly designed by Mistonline.in.
Affordable Seo PackagesSeo BlogEdu Backlinks