This article uses CSS+HTML+JS to implement a landscape menu. has a multi-level pop-up menu drop-down.
First, let's take a look:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvajkwmzgyote4mg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">
You should first write the HTML part of the code, the code is relatively simple, code such as the following:
<body> <div id= "menu" > <ul> <li><a href= "#" id= "current" > Home </a>< /li> <li><a href= "#" > Page layout </a> <ul> <li><a href= "#" > Adaptive width </a></li> <li><a href= "#" > Fixed width </a></li> </ul> </li > <li><a href= "#" >web tutorials </a> <ul> <li><a href= "#" , beginner </a></li> <li><a href= "#" > Video Tutorials </a></li> <li><a HRE f= "#" > FAQs </a></li> </ul> </li> <li><a href= "#" >web Real Example </a></li> <li><a href= "#" > Frequently used code </a></li> </ul> </div> <div id= "S1" > <ul> <li><a href= "#" > Software project</a> <ul& Gt <li> <a href= "#" >java ee</a></li> <li><a href= "#" >c</a></li> &L t;/ul> </li> <li><a href= "#" > Program language </a> <ul> <li><a href= "#" >android</a></li> <li><a href= "#" >java</a></li> </ul> </li> </ul> </div> </body>
Then write the CSS code, the code has a gaze, easy to read and understand:
<style type= "Text/css" >body {font-family:verdana;/* font */font-size:12px;/* Font size */line-height:1.5;/* Row height */} A {color: #000;/* color when normal */text-decoration:none;//* a:hover {color: #F00;/* The color displayed when the mouse passes through */} #m ENU {width:500px;/* div width */height:28px;/* Height */margin:0 auto;/* Horizontal Center */border-bottom:3px solid #E10001;/* Set Bottom The tip */} #menu ul {list-style:none;/* Cancel list style */margin:0px;/* margin is 0 */padding:0px;/* padding is 0 */} #menu UL Li {float:left;/* Horizontal float */margin-left:2px;/* left margin is 2px */} #menu ul li a {display:block; width:87px; height:28px; line-height:28px; Text-align:center; Background:url (./m14.jpg) 0 0 no-repeat; font-size:14px; } #menu ul li a:hover {background:url (./m13.jpg) 0 0 no-repeat; } #menu ul Li a#current {background:url (./m12.jpg) 0 0 no-repeat; Font-weight:bold; Color: #fff; } #menu ul Li ul {border:1px solid #ccc; Display:none; Position:absolute; } #menu ul Li ul li{float:none; width:87px; Background: #eee; margin:0; } #menu ul Li ul li a {background:none; } #menu ul Li ul li a:hover {background: #333; Color: #fff; } #menu UL Li:hover ul {display:block; } #menu UL Li.sfhover ul {display:block; } #s1 {background-color:pink; width:180px; BORDER:2PX solid red; position:relative; left:200px; top:190px; height:60px;} #s1 ul li{List-style-type:none; height:25px; width:50px; Background-color: #0ff; Float:left; margin:10px;} #s1 ul Li ul{display:none; Position:absolute;} #s1 ul li:hover ul{Display:block; Background-color:blue; margin:0px; padding:0px; /* width:100px; */} #s1 UL Li.sfhover ul {display:block; margin:0px; padding:0px; } #s1 ul Li ul li{border:1px solid red; Float:none; margin:0px; width:50px; } </style>
After the above steps can be tested, you will find that the above code only in Google Browser can operate normally. Ability to implement drop-down menus. However, in IE and other browsers, can not use the drop-down menu, browser incompatibility caused by, so in order to write a compatible full browser menu, but also need to control the JS code. JS code such as the following;
<script type= "Text/javascript" > Function Menufix () {var sfels = document.getElementById ("menu"). Getelementsby TagName ("Li"); var sfEls2 = document.getElementById ("S1"). getElementsByTagName ("Li"); for (var i=0; i<sfels.length; i++) {sfels[i].onmouseover=function () {this.classname+= (this.classn Ame.length>0? "": "") + "Sfhover"; }; Sfels[i].onmousedown=function () {this.classname+= (this.classname.length>0?)"": "") + "Sfhover"; }; Sfels[i].onmouseup=function () {this.classname+= (this.classname.length>0?) "": "") + "Sfhover"; }; Sfels[i].onmouseout=function () {This.classname=this.classname.replace (new RegExp (? | ^) (sfhover\\b ")," "); }; } for (var i=0; i<sfels2.length; i++) {sfels2[i].onmouseover=function () { this.classname+= (this.classname.length>0?
"": "") + "Sfhover"; }; Sfels2[i].onmousedown=function () {this.classname+= (this.classname.length>0?)
"": "") + "Sfhover"; }; Sfels2[i].onmouseup=function () {this.classname+= (this.classname.length>0?)
"": "") + "Sfhover"; }; Sfels2[i].onmouseout=function () {This.classname=this.classname.replace (new RegExp (? | ^) (sfhover\\b ")," "); }; }}window.onload=menufix;</script>
Now be able to perform normal, will appear this article began to show the effect, because it is a test, so some CSS code is not removed, mainly to facilitate debugging
CSS+HTML+JS implementing Multi-level drop-down and popup menus