用Dreamweaver 怎样创建导航条以及导航条的下拉菜单? 20
展开全部
有两种方式可以实现
一、纯CSS样式实现,代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>二级下拉菜单</title>
<style type="text/css">
/*
#193B5F 栏目字体颜色
*/
*{margin:0; padding:0}
body{width:960px; margin:20px auto; font-size:14px;}
/*导航条*/
#nav {background-color:blue; color:#fff;height:25px;line-height:25px;text-align:center;list-style:none;}
#nav a{color:#fff;}
#nav li{width:75px;float:left;position:relative;z-index:1;}
#nav li .title{display:block;}
#nav li .title:hover{background-color:green;}
#nav li .submenu{width:75px;margin:0 auto;background:green;position:absolute;left:0;top:25px;display:none;}
#nav li .submenu dd{border-top:1px dotted #ddd;color:#fff;}
</style>
</head>
<body>
<ul id="nav">
<!-- 有二级菜单的,给li加class="menu" 没有的不用加 -->
<li class="menu">
<a href="#" class="title">国家政务</a>
<dl class="submenu">
<dd><a href="#">时政要闻</a></dd>
<dd><a href="#">远程党教</a></dd>
<dd><a href="#">村务管理</a></dd>
</dl>
</li>
<li>
<a href="#" class="title">网络服务</a>
</li>
<li class="menu">
<a href="#" class="title">信息交流</a>
<dl class="submenu">
<dd><a href="#">求购信息</a></dd>
<dd><a href="#">转让信息</a></dd>
</dl>
</li>
</div><!--end nav-->
<script type="text/javascript">
<!--
var nav = document.getElementById("nav").childNodes;
for (var i=0;i<nav.length;i++)
{
if (nav[i].className=="menu")
{
nav[i].onmouseover = function(){fnNav(this,"block")};
nav[i].onmouseout = function(){fnNav(this,"none")};
}
}
function fnNav(obj,flag)
{
obj.getElementsByTagName("dl")[0].style.display = flag;
}
//-->
</script>
</body>
</html>
二、CSS+JS实现,代码如下
<style type="text/css">
<!--
*{margin:0;padding:0;border:0;}
body {
font-family: arial, 宋体, serif;
font-size:12px;
}
#nav {
line-height: 24px; list-style-type: none; background:#666;
}
#nav a {
display: block; width: 80px; text-align:center;
}
#nav a:link {
color:#666; text-decoration:none;
}
#nav a:visited {
color:#666;text-decoration:none;
}
#nav a:hover {
color:#FFF;text-decoration:none;font-weight:bold;
}
#nav li {
float: left; width: 80px; background:#CCC;
}
#nav li a:hover{
background:#999;
}
#nav li ul {
line-height: 27px; list-style-type: none;text-align:left;
left: -999em; width: 180px; position: absolute;
}
#nav li ul li{
float: left; width: 180px;
background: #F6F6F6;
}
#nav li ul a{
display: block; width: 156px;text-align:left;padding-left:24px;
}
#nav li ul a:link {
color:#666; text-decoration:none;
}
#nav li ul a:visited {
color:#666;text-decoration:none;
}
#nav li ul a:hover {
color:#F3F3F3;text-decoration:none;font-weight:normal;
background:#C00;
}
#nav li:hover ul {
left: auto;
}
#nav li.sfhover ul {
left: auto;
}
#content {
clear: left;
}
-->
</style>
<script type=text/javascript><!--//--><![CDATA[//><!--
function menuFix() {
var sfEls = document.getElementById("nav").getElementsByTagName("li");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=(this.className.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"),
"");
}
}
}
window.onload=menuFix;
//--><!]]></script>
</head>
<body>
<ul id="nav">
<li><a href="#" _fcksavedurl="#">产品介绍</a>
<ul>
<li><a href="#" _fcksavedurl="#">产品一</a></li>
<li><a href="#" _fcksavedurl="#">产品一</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">服务介绍</a>
<ul>
<li><a href="#" _fcksavedurl="#">服务二</a></li>
<li><a href="#" _fcksavedurl="#">服务二</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">成功案例</a>
<ul>
<li><a href="#" _fcksavedurl="#">案例三</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">关于我们</a>
<ul>
<li><a href="#" _fcksavedurl="#">我们四</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">在线演示</a>
<ul>
<li><a href="#" _fcksavedurl="#">演示</a></li>
<li><a href="#" _fcksavedurl="#">演示</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">联系我们</a>
<ul>
<li><a href="#" _fcksavedurl="#">联系联系联系联系联系</a></li>
<li><a href="#" _fcksavedurl="#">联系联系联系</a></li>
</ul>
</li>
</ul>
</body>
</html>
一、纯CSS样式实现,代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>二级下拉菜单</title>
<style type="text/css">
/*
#193B5F 栏目字体颜色
*/
*{margin:0; padding:0}
body{width:960px; margin:20px auto; font-size:14px;}
/*导航条*/
#nav {background-color:blue; color:#fff;height:25px;line-height:25px;text-align:center;list-style:none;}
#nav a{color:#fff;}
#nav li{width:75px;float:left;position:relative;z-index:1;}
#nav li .title{display:block;}
#nav li .title:hover{background-color:green;}
#nav li .submenu{width:75px;margin:0 auto;background:green;position:absolute;left:0;top:25px;display:none;}
#nav li .submenu dd{border-top:1px dotted #ddd;color:#fff;}
</style>
</head>
<body>
<ul id="nav">
<!-- 有二级菜单的,给li加class="menu" 没有的不用加 -->
<li class="menu">
<a href="#" class="title">国家政务</a>
<dl class="submenu">
<dd><a href="#">时政要闻</a></dd>
<dd><a href="#">远程党教</a></dd>
<dd><a href="#">村务管理</a></dd>
</dl>
</li>
<li>
<a href="#" class="title">网络服务</a>
</li>
<li class="menu">
<a href="#" class="title">信息交流</a>
<dl class="submenu">
<dd><a href="#">求购信息</a></dd>
<dd><a href="#">转让信息</a></dd>
</dl>
</li>
</div><!--end nav-->
<script type="text/javascript">
<!--
var nav = document.getElementById("nav").childNodes;
for (var i=0;i<nav.length;i++)
{
if (nav[i].className=="menu")
{
nav[i].onmouseover = function(){fnNav(this,"block")};
nav[i].onmouseout = function(){fnNav(this,"none")};
}
}
function fnNav(obj,flag)
{
obj.getElementsByTagName("dl")[0].style.display = flag;
}
//-->
</script>
</body>
</html>
二、CSS+JS实现,代码如下
<style type="text/css">
<!--
*{margin:0;padding:0;border:0;}
body {
font-family: arial, 宋体, serif;
font-size:12px;
}
#nav {
line-height: 24px; list-style-type: none; background:#666;
}
#nav a {
display: block; width: 80px; text-align:center;
}
#nav a:link {
color:#666; text-decoration:none;
}
#nav a:visited {
color:#666;text-decoration:none;
}
#nav a:hover {
color:#FFF;text-decoration:none;font-weight:bold;
}
#nav li {
float: left; width: 80px; background:#CCC;
}
#nav li a:hover{
background:#999;
}
#nav li ul {
line-height: 27px; list-style-type: none;text-align:left;
left: -999em; width: 180px; position: absolute;
}
#nav li ul li{
float: left; width: 180px;
background: #F6F6F6;
}
#nav li ul a{
display: block; width: 156px;text-align:left;padding-left:24px;
}
#nav li ul a:link {
color:#666; text-decoration:none;
}
#nav li ul a:visited {
color:#666;text-decoration:none;
}
#nav li ul a:hover {
color:#F3F3F3;text-decoration:none;font-weight:normal;
background:#C00;
}
#nav li:hover ul {
left: auto;
}
#nav li.sfhover ul {
left: auto;
}
#content {
clear: left;
}
-->
</style>
<script type=text/javascript><!--//--><![CDATA[//><!--
function menuFix() {
var sfEls = document.getElementById("nav").getElementsByTagName("li");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=(this.className.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"),
"");
}
}
}
window.onload=menuFix;
//--><!]]></script>
</head>
<body>
<ul id="nav">
<li><a href="#" _fcksavedurl="#">产品介绍</a>
<ul>
<li><a href="#" _fcksavedurl="#">产品一</a></li>
<li><a href="#" _fcksavedurl="#">产品一</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">服务介绍</a>
<ul>
<li><a href="#" _fcksavedurl="#">服务二</a></li>
<li><a href="#" _fcksavedurl="#">服务二</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">成功案例</a>
<ul>
<li><a href="#" _fcksavedurl="#">案例三</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">关于我们</a>
<ul>
<li><a href="#" _fcksavedurl="#">我们四</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">在线演示</a>
<ul>
<li><a href="#" _fcksavedurl="#">演示</a></li>
<li><a href="#" _fcksavedurl="#">演示</a></li>
</ul>
</li>
<li><a href="#" _fcksavedurl="#">联系我们</a>
<ul>
<li><a href="#" _fcksavedurl="#">联系联系联系联系联系</a></li>
<li><a href="#" _fcksavedurl="#">联系联系联系</a></li>
</ul>
</li>
</ul>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询