Drop-down menu implementation method 1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.