1. css代码设置如下:下面的案例已经包含css了,本条只是提出本文重点代码,供大家参看,大家可以直接复制下面的实例去测试。
/*悬停下拉导航设置*/
.navbar .nav > li .dropdown-menu {margin: 0;}
.navbar .nav > li:hover .dropdown-menu {display: block;}
实例运行:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.0-alpha1/js/bootstrap.js"></script>
</head>
<body>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.0/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
.navbar .nav>li .dropdown-menu {
margin: 0;
}
.navbar .nav>li:hover .dropdown-menu {
display: block;
}
</style>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left">
<li class="active"><a href="#">首页 <span class="sr-only">(current)</span></a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">产品服务
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">设备介绍</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">粉末耗材</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">轻量化设计</a></li>
</ul>
</li>
<li><a href="#">技术支持</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">解决方案
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">航天航空</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">汽车制造</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">电子</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">能源动力</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">齿科</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">工业模具</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">资讯中心
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">领导关怀</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">会展活动</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">新闻动态</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">关于我们
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">公司简介</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">公司记事</a></li>
</ul>
</li>
<li><a href="#">联系我们</a></li>
</ul>
</div>
</div>
</nav>
</body>
</html>