[英]multi-level (drop down) menu css js
I want to have multi-level (drop down) menu, such that I can change the menu just one file, and do not have to go to every single page to change the menu. 我想要一个多级(下拉)菜单, 这样我可以只更改一个文件即可更改菜单,而不必转到每个页面来更改菜单。 I will need three level menu .
我将需要三级菜单 。
I have modified someone code but not working as I like 我已经修改了某人的代码,但是无法按我的意愿工作
CSS code (OurSite.css) CSS代码(OurSite.css)
ul#third-level-menu
{
position: absolute;
top: 0;
right: -150px;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
ul#third-level-menu > li
{
height: 30px;
background: #999999;
}
ul#third-level-menu > li:hover { background: #CCCCCC; }
ul#second-level-menu
{
position: absolute;
top: 30px;
left: 0;
width: 150px;
list-style: none;
padding: 0;
margin: 0;
display: none;
}
ul#second-level-menu > li
{
position: relative;
height: 30px;
background: #999999;
}
ul#second-level-menu > li:hover { background: #CCCCCC; }
ul#top-level-menu
{
list-style: none;
padding: 0;
margin: 0;
}
ul#top-level-menu > li
{
position: relative;
float: left;
height: 30px;
width: 150px;
background: #999999;
}
ul#top-level-menu > li:hover { background: #CCCCCC; }
ul#top-level-menu li:hover > ul
{
/* On hover, display the next level's menu */
display: inline;
}
/* Menu Link Styles */
ul#top-level-menu a /* Apply to all links inside the multi-level menu */
{
font: bold 14px Arial, Helvetica, sans-serif;
color: #FFFFFF;
text-decoration: none;
padding: 0 0 0 10px;
/* Make the link cover the entire list item-container */
display: block;
line-height: 30px;
}
ul#top-level-menu a:hover { color: #000000; }
I also have js code (Menu-Script.js) 我也有js代码(Menu-Script.js)
document.getElementById("nav01").innerHTML =
"<ul id='top-level-menu'>" +
"<li><a href='index.html'>Home</a></li>" +
"<ul id='second-level-menu'>" +
"<li><a href='index12.html'>Home12</a></li>" +
"<ul id='third-level-menu'>" +
"<li><a href='index123.html'>Home123</a></li>" +
"<li><a href='index124.html'>Home124</a></li>" +
"</ul>" +
"<li><a href='index13.html'>Home13</a></li>" +
"</ul>" +
"<li><a href='customers.html'>Data</a></li>" +
"<li><a href='about.html'>About</a></li>" +
"</ul>";
For HTML Code 对于HTML代码
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<link href="OurSite.css" rel="stylesheet">
</head>
<body>
<nav id="nav01"></nav>
<div id="main">
<h1>Welcome to Our Site</h1>
<h2>Web Site Main Ingredients:</h2>
<p>Pages (HTML)</p>
<p>Style (CSS)</p>
<p>Code (JavaScript)</p>
</div>
<script src="Menu-Script.js"></script>
</body>
</html>
Or if you have a better code pleaes let me know, many thanks 或者,如果您有更好的代码请求,请告诉我,非常感谢
Uhm... your code is not best, but, i think you only change the html inside js: 嗯...您的代码不是最好的,但是,我认为您只能更改js中的html:
document.getElementById("nav01").innerHTML =
"<ul id='top-level-menu'>" +
"<li><a href='index.html'>Home</a>" + // not close li here
"<ul id='second-level-menu'>" +
"<li><a href='index12.html'>Home12</a>" + // not close li here
"<ul id='third-level-menu'>" +
"<li><a href='index123.html'>Home123</a></li>" +
"<li><a href='index124.html'>Home124</a></li>" +
"</ul></li>" + // close li here
"<li><a href='index13.html'>Home13</a></li>" +
"</ul></li>" + // close li here
"<li><a href='customers.html'>Data</a></li>" +
"<li><a href='about.html'>About</a></li>" +
"</ul>";
Insert <ul>
inside his parent <li>
. 将
<ul>
插入其父<li>
。
[ul]
-> li
[ul]
-> li
[ul]
-> li
-> li
-> li
-> li
Example: http://fiddle.jshell.net/9tok0z5d/ 示例: http : //fiddle.jshell.net/9tok0z5d/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.