Implement a simple drop-down menu
Because the example is relatively simple, I wrote it in a text editor. nodepad ++ is a good choice, with color labels and smart prompts. It is easy to use.
First, write an HTML Tag structure.
<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Next, write a list.
<Body> <ul class = "menu"> <li> <a href = "#"> Level 1 menu </a> <ul> <li> <a href = "# "> Level 2 menu a </a> </LI> <li> <a href =" # "> Level 2 Menu B </a> </LI> </ul> </LI> </ul> </body>
Then write CSS to clear useless things.
*{margin:0; padding:0;border:0}li{list-style-type:none}
Add Borders and the like.
.menu li{ border:1px solid #cccccc; width:180px; height:30px; line-height:30px; background-color:#f8f8f8 }
Then, hide the level-2 menu.
.menu li ul{ position:absolute; left:-999em}
Write a second-level menu display style.
.menu li.on ul{ left:auto}
In this way, you can use js to control on to implement the drop-down menu.
$(function(){ $(".menu li").mouseover(function(){ $(this).addClass("on"); }) $(".menu li").mouseout(function(){ $(this).removeClass("on"); })})
Drop-down menu implementation method 1